Skip to content

Apache Druid Calcite Query Testing: Cannot read field "componentSupplier" because "config" is null #17920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
paulo-alves-flttr opened this issue Apr 15, 2025 · 1 comment

Comments

@paulo-alves-flttr
Copy link

I have an druid extension project that adds new user defined function to Druid SQL, but I have been facing some problems when implementing tests. I have used this example as reference but it is broken, since configureGuice method no longer exists as Druid 32.

I have tried the following by reading the source code from Druid:

@ComponentSupplier(MyComponentSupplier.class)
public class CustomSqlAggregatorTest extends BaseCalciteQueryTest {

    @Test
    public void testCustomAggSql() {
        cannotVectorize();
        testBuilder()
                .sql("select CUSTOM_AGG(m1) from foo")
                .expectedQueries(
                        List.of(
                                Druids.newTimeseriesQueryBuilder()
                                        .dataSource(CalciteTests.DATASOURCE1)
                                        .intervals(querySegmentSpec(Filtration.eternity()))
                                        .granularity(Granularities.ALL)
                                        .aggregators(aggregators(getAggFactory()))
                                        .context(QUERY_CONTEXT_DEFAULT)
                                        .build()
                        )
                )
                .expectedResults(ImmutableList.of(new Object[]{21.0F}))
                .run();
    }
    ...
}

But I get the following error:

Caused by: java.lang.NullPointerException: Cannot read field "componentSupplier" because "config" is null
	at org.apache.druid.sql.calcite.SqlTestFrameworkConfig$ConfigurationInstance.<init>(SqlTestFrameworkConfig.java:378)
	at org.apache.druid.sql.calcite.SqlTestFrameworkConfig$SqlTestFrameworkConfigStore.getConfigurationInstance(SqlTestFrameworkConfig.java:253)
	at org.apache.druid.sql.calcite.SqlTestFrameworkConfig$Rule.get(SqlTestFrameworkConfig.java:344)
	at org.apache.druid.sql.calcite.BaseCalciteQueryTest.queryFramework(BaseCalciteQueryTest.java:535)
	... 34 more

My component supplier code looks like the following:

public class MyComponentSupplier extends SqlTestFramework.StandardComponentSupplier {
    public MyComponentSupplier(TempDirProducer tempDirProducer) {
        super(tempDirProducer);
    }

    @Override
    public DruidModule getCoreModule() {
        return DruidModuleCollection.of(
                super.getCoreModule(),
                new MyExtensionModule()
        );
    }
}

Any suggestions?

@paulo-alves-flttr
Copy link
Author

I was able to get the test running by adding some code before running the test. The code basically forces Component Supplier to be loaded into the config map. The workaround looks like the following:

@ComponentSupplier(MyComponentSupplier.class)
public class CustomSqlAggregatorTest extends BaseCalciteQueryTest {

    @Test
    public void testCustomAggSql() {
        initializeGuiceConfiguration();
        cannotVectorize();
        testBuilder()
                .sql("select CUSTOM_AGG(m1) from foo")
                .expectedQueries(
                        List.of(
                                Druids.newTimeseriesQueryBuilder()
                                        .dataSource(CalciteTests.DATASOURCE1)
                                        .intervals(querySegmentSpec(Filtration.eternity()))
                                        .granularity(Granularities.ALL)
                                        .aggregators(aggregators(getAggFactory()))
                                        .context(QUERY_CONTEXT_DEFAULT)
                                        .build()
                        )
                )
                .expectedResults(ImmutableList.of(new Object[]{21.0F}))
                .run();
    }
    
    private static void initializeGuiceConfiguration() {
        List<Annotation> annotations = List.of(ArrayWithLimitSqlAggregatorTest.class.getAnnotations());
        queryFrameworkRule.setConfig(new SqlTestFrameworkConfig(annotations));
    }
    ...
}

For some reason @ComponentSupplier annotation doesn't seems to be working properly and I couldn't figure out the configuration needed for it to work as it should.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant