Search in sources :

Example 1 with SqlExtractionOperator

use of io.druid.sql.calcite.expression.SqlExtractionOperator in project druid by druid-io.

the class DruidOperatorTable method lookupOperatorOverloads.

@Override
public void lookupOperatorOverloads(final SqlIdentifier opName, final SqlFunctionCategory category, final SqlSyntax syntax, final List<SqlOperator> operatorList) {
    if (opName.names.size() == 1 && syntax == SqlSyntax.FUNCTION) {
        final SqlAggregator aggregator = aggregators.get(opName.getSimple().toLowerCase());
        if (aggregator != null) {
            operatorList.add(aggregator.calciteFunction());
        }
        final SqlExtractionOperator extractionFunction = extractionOperators.get(opName.getSimple().toLowerCase());
        if (extractionFunction != null) {
            operatorList.add(extractionFunction.calciteFunction());
        }
    }
    STANDARD_TABLE.lookupOperatorOverloads(opName, category, syntax, operatorList);
}
Also used : SqlExtractionOperator(io.druid.sql.calcite.expression.SqlExtractionOperator) SqlAggregator(io.druid.sql.calcite.aggregation.SqlAggregator)

Example 2 with SqlExtractionOperator

use of io.druid.sql.calcite.expression.SqlExtractionOperator in project druid by druid-io.

the class CalciteTests method createOperatorTable.

public static DruidOperatorTable createOperatorTable() {
    try {
        final Injector injector = Guice.createInjector(new Module() {

            @Override
            public void configure(final Binder binder) {
                // This Module is just to get a LookupReferencesManager with a usable "lookyloo" lookup.
                final LookupReferencesManager mock = EasyMock.createMock(LookupReferencesManager.class);
                EasyMock.expect(mock.get(EasyMock.eq("lookyloo"))).andReturn(new LookupExtractorFactory() {

                    @Override
                    public boolean start() {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public boolean close() {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public boolean replaces(@Nullable final LookupExtractorFactory other) {
                        throw new UnsupportedOperationException();
                    }

                    @Nullable
                    @Override
                    public LookupIntrospectHandler getIntrospectHandler() {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public LookupExtractor get() {
                        return new MapLookupExtractor(ImmutableMap.of("a", "xa", "abc", "xabc"), false);
                    }
                }).anyTimes();
                EasyMock.replay(mock);
                binder.bind(LookupReferencesManager.class).toInstance(mock);
            }
        });
        final Set<SqlAggregator> aggregators = new HashSet<>();
        final Set<SqlExtractionOperator> extractionOperators = new HashSet<>();
        for (Class<? extends SqlAggregator> clazz : SqlModule.DEFAULT_AGGREGATOR_CLASSES) {
            aggregators.add(injector.getInstance(clazz));
        }
        for (Class<? extends SqlExtractionOperator> clazz : SqlModule.DEFAULT_EXTRACTION_OPERATOR_CLASSES) {
            extractionOperators.add(injector.getInstance(clazz));
        }
        return new DruidOperatorTable(aggregators, extractionOperators);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : LookupExtractorFactory(io.druid.query.lookup.LookupExtractorFactory) LookupReferencesManager(io.druid.query.lookup.LookupReferencesManager) DruidOperatorTable(io.druid.sql.calcite.planner.DruidOperatorTable) LookupExtractor(io.druid.query.lookup.LookupExtractor) MapLookupExtractor(io.druid.query.extraction.MapLookupExtractor) LookupIntrospectHandler(io.druid.query.lookup.LookupIntrospectHandler) Binder(com.google.inject.Binder) SqlExtractionOperator(io.druid.sql.calcite.expression.SqlExtractionOperator) Injector(com.google.inject.Injector) SqlAggregator(io.druid.sql.calcite.aggregation.SqlAggregator) MapLookupExtractor(io.druid.query.extraction.MapLookupExtractor) Module(com.google.inject.Module) SqlModule(io.druid.sql.guice.SqlModule) Nullable(javax.annotation.Nullable) HashSet(java.util.HashSet)

Example 3 with SqlExtractionOperator

use of io.druid.sql.calcite.expression.SqlExtractionOperator in project druid by druid-io.

the class DruidOperatorTable method getOperatorList.

@Override
public List<SqlOperator> getOperatorList() {
    final List<SqlOperator> retVal = new ArrayList<>();
    for (SqlAggregator aggregator : aggregators.values()) {
        retVal.add(aggregator.calciteFunction());
    }
    for (SqlExtractionOperator extractionFunction : extractionOperators.values()) {
        retVal.add(extractionFunction.calciteFunction());
    }
    retVal.addAll(STANDARD_TABLE.getOperatorList());
    return retVal;
}
Also used : SqlExtractionOperator(io.druid.sql.calcite.expression.SqlExtractionOperator) SqlOperator(org.apache.calcite.sql.SqlOperator) SqlAggregator(io.druid.sql.calcite.aggregation.SqlAggregator) ArrayList(java.util.ArrayList)

Aggregations

SqlAggregator (io.druid.sql.calcite.aggregation.SqlAggregator)3 SqlExtractionOperator (io.druid.sql.calcite.expression.SqlExtractionOperator)3 Binder (com.google.inject.Binder)1 Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 MapLookupExtractor (io.druid.query.extraction.MapLookupExtractor)1 LookupExtractor (io.druid.query.lookup.LookupExtractor)1 LookupExtractorFactory (io.druid.query.lookup.LookupExtractorFactory)1 LookupIntrospectHandler (io.druid.query.lookup.LookupIntrospectHandler)1 LookupReferencesManager (io.druid.query.lookup.LookupReferencesManager)1 DruidOperatorTable (io.druid.sql.calcite.planner.DruidOperatorTable)1 SqlModule (io.druid.sql.guice.SqlModule)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Nullable (javax.annotation.Nullable)1 SqlOperator (org.apache.calcite.sql.SqlOperator)1