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);
}
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);
}
}
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;
}
Aggregations