@ConstantFunction(name = "makedate", argTypes = {INT, INT}, returnType = DATETIME)
    public static ConstantOperator makeDate(ConstantOperator year, ConstantOperator dayOfYear) {
        if (year.isNull() || dayOfYear.isNull()) {
            return ConstantOperator.createNull(Type.DATE);
        }

        int yearInt = year.getInt();
        if (yearInt < YEAR_MIN || yearInt > YEAR_MAX) {
            return ConstantOperator.createNull(Type.DATE);
        }

        int dayOfYearInt = dayOfYear.getInt();
        if (dayOfYearInt < DAY_OF_YEAR_MIN || dayOfYearInt > DAY_OF_YEAR_MAX) {
            return ConstantOperator.createNull(Type.DATE);
        }

        LocalDate ld = LocalDate.of(yearInt, 1, 1)
                .plusDays(dayOfYearInt - 1);

        if (ld.getYear() != year.getInt()) {
            return ConstantOperator.createNull(Type.DATE);
        }

        return ConstantOperator.createDateOrNull(ld.atTime(0, 0, 0));
    }
@Test
    public void makeDate() {
        ConnectContext ctx = new ConnectContext(null);
        ctx.setThreadLocalInfo();
        ctx.setStartTime();

        assertEquals(ConstantOperator.createNull(Type.DATE),
                ScalarOperatorFunctions.makeDate(ConstantOperator.createNull(Type.INT),
                        ConstantOperator.createNull(Type.INT)));

        assertEquals(ConstantOperator.createNull(Type.DATE),
                ScalarOperatorFunctions.makeDate(ConstantOperator.createNull(Type.INT),
                        ConstantOperator.createInt(1)));

        assertEquals(ConstantOperator.createNull(Type.DATE),
                ScalarOperatorFunctions.makeDate(ConstantOperator.createInt(1),
                        ConstantOperator.createNull(Type.INT)));

        assertEquals(ConstantOperator.createNull(Type.DATE),
                ScalarOperatorFunctions.makeDate(ConstantOperator.createInt(2000), ConstantOperator.createInt(0)));

        assertEquals(ConstantOperator.createNull(Type.DATE),
                ScalarOperatorFunctions.makeDate(ConstantOperator.createInt(2000), ConstantOperator.createInt(367)));

        assertEquals(ConstantOperator.createNull(Type.DATE),
                ScalarOperatorFunctions.makeDate(ConstantOperator.createInt(-1), ConstantOperator.createInt(1)));

        assertEquals(ConstantOperator.createNull(Type.DATE),
                ScalarOperatorFunctions.makeDate(ConstantOperator.createInt(10000), ConstantOperator.createInt(1)));

        assertEquals(ConstantOperator.createDate(LocalDateTime.of(2000, 1, 1, 0, 0, 0)),
                ScalarOperatorFunctions.makeDate(ConstantOperator.createInt(2000), ConstantOperator.createInt(1)));

        assertEquals(ConstantOperator.createDate(LocalDateTime.of(2000, 12, 31, 0, 0, 0)),
                ScalarOperatorFunctions.makeDate(ConstantOperator.createInt(2000), ConstantOperator.createInt(366)));

        assertEquals(ConstantOperator.createDate(LocalDateTime.of(0, 1, 1, 0, 0, 0)),
                ScalarOperatorFunctions.makeDate(ConstantOperator.createInt(0), ConstantOperator.createInt(1)));
    }