@Override public void register(OperatorTable operatorTable) { for (String name : supportedFunctions.keySet()) { for (GandivaFunctionHolder holder : supportedFunctions.get(name)) { SqlOperator operator = GandivaOperator.getSimpleFunction(name, holder.getParamCount(), new PlugginRepositorySqlReturnTypeInference(this)); operatorTable.add(name, operator); } } }
private UserException getConvertFunctionException(final String functionName, final String typeName) { final String newFunctionName = functionName + typeName; final boolean emptyTypeName = typeName.isEmpty(); final String typeNameToPrint = emptyTypeName ? "<empty_string>" : typeName; final UserException.Builder exceptionBuilder = UserException.unsupportedError() .message("%s does not support conversion %s type '%s'.", functionName, functionName.substring(8).toLowerCase(), typeNameToPrint); // Build a nice error message if (!emptyTypeName) { List<String> ops = new ArrayList<>(); for (SqlOperator op : table.getOperatorList()) { ops.add(op.getName()); } final String bestMatch = ApproximateStringMatcher.getBestMatch(ops, newFunctionName); if (bestMatch != null && bestMatch.length() > 0 && bestMatch.toLowerCase().startsWith("convert")) { final StringBuilder s = new StringBuilder("Did you mean ") .append(bestMatch.substring(functionName.length())) .append("?"); exceptionBuilder.addContext(s.toString()); } } return exceptionBuilder.build(logger); } }
@Before public void setup() { // Create and Mock dependencies final SabotContext sabotContext = mock(SabotContext.class); final FunctionImplementationRegistry functionImplementationRegistry = mock(FunctionImplementationRegistry.class); final JavaTypeFactory typeFactory = JavaTypeFactoryImpl.INSTANCE; // Stub necessary methods when(sabotContext.getFunctionImplementationRegistry()).thenReturn(functionImplementationRegistry); // Utilize custom catalog reader implementation to return specific suggestions, // without requiring server startup MockCatalogReader mockCatalogReader = new MockCatalogReader(typeFactory, false); SqlValidatorWithHints validator = new SqlAdvisorValidator(new OperatorTable(sabotContext.getFunctionImplementationRegistry()), mockCatalogReader, typeFactory, DremioSqlConformance.INSTANCE); sqlAnalyzer = new SQLAnalyzer(validator); }
List<SqlOperator> operatorList = table.getSqlOperator(newFunctionName); if (operatorList.size() == 0) {
protected QueryContext mockQueryContext(SabotContext dbContext) throws Exception { final UserSession userSession = UserSession.Builder.newBuilder().withOptionManager(dbContext.getOptionManager()).build(); final SessionOptionManager sessionOptions = (SessionOptionManager) userSession.getOptions(); final QueryOptionManager queryOptions = new QueryOptionManager(sessionOptions); final ExecutionControls executionControls = new ExecutionControls(queryOptions, NodeEndpoint.getDefaultInstance()); final OperatorTable table = new OperatorTable(FUNCTIONS()); final LogicalPlanPersistence lp = dbContext.getLpPersistence(); final CatalogService registry = dbContext.getCatalogService(); final QueryContext context = Mockito.mock(QueryContext.class); when(context.getSession()).thenReturn(userSession); when(context.getLpPersistence()).thenReturn(lp); when(context.getCatalogService()).thenReturn(registry); when(context.getFunctionRegistry()).thenReturn(FUNCTIONS()); when(context.getSession()).thenReturn(UserSession.Builder.newBuilder().setSupportComplexTypes(true).build()); when(context.getCurrentEndpoint()).thenReturn(NodeEndpoint.getDefaultInstance()); when(context.getActiveEndpoints()).thenReturn(ImmutableList.of(NodeEndpoint.getDefaultInstance())); when(context.getPlannerSettings()).thenReturn(new PlannerSettings(dbContext.getConfig(), queryOptions, dbContext.getClusterResourceInformation())); when(context.getOptions()).thenReturn(queryOptions); when(context.getConfig()).thenReturn(DEFAULT_SABOT_CONFIG); when(context.getOperatorTable()).thenReturn(table); when(context.getAllocator()).thenReturn(allocator); when(context.getExecutionControls()).thenReturn(executionControls); when(context.getMaterializationProvider()).thenReturn(Mockito.mock(MaterializationDescriptorProvider.class)); return context; }
sabotContext.getClusterResourceInformation()); this.plannerSettings.setNumEndPoints(sabotContext.getExecutors().size()); this.table = new OperatorTable(sabotContext.getFunctionImplementationRegistry());
@Override public void register(OperatorTable operatorTable) { for (String name : Sets.union(methodsGenericUDF.asMap().keySet(), methodsUDF.asMap().keySet())) { operatorTable.add(name, new HiveUDFOperator(name.toUpperCase(), new PlugginRepositorySqlReturnTypeInference(this))); } }
DremioCatalogReader catalogReader = new DremioCatalogReader(catalog, typeFactory); OperatorTable opTable = new OperatorTable(sabotContext.getFunctionImplementationRegistry()); SqlOperatorTable chainedOpTable = new ChainedSqlOperatorTable(ImmutableList.<SqlOperatorTable>of(opTable, catalogReader));
public void register(OperatorTable operatorTable) { operatorTable.add("NDV", HyperLogLog.NDV); operatorTable.add("DATE_PART", SqlDatePartOperator.INSTANCE); operatorTable.add("FLATTEN", SqlFlattenOperator.INSTANCE); operatorTable.add("E", E_FUNCTION); TypeInferenceUtils.getSqlReturnTypeInference(name, Lists.newArrayList(entry.getValue())), sqlSyntax); operatorTable.add(name, sqlOperator); operatorTable.add(name, new SqlAggOperator( name, entry.getKey(),