/** * Return a view macro that may or may not be defined in a certain schema. If it's not defined, returns null. * * @param schemaPlus schema * @param functionName function name * * @return view, or null */ @Nullable private static TableMacro getView(final SchemaPlus schemaPlus, final String functionName) { // Look for a zero-arg function that is also a TableMacro. The returned value // is never null so we don't need to check for that. final Collection<org.apache.calcite.schema.Function> functions = schemaPlus.getFunctions(functionName); for (org.apache.calcite.schema.Function function : functions) { if (function.getParameters().isEmpty() && function instanceof TableMacro) { return (TableMacro) function; } } return null; }
@Override public List<String> getParamNames() { return Lists.transform(function.getParameters(), FunctionParameter::getName); } }
@Override public List<String> getParamNames() { return Lists.transform(function.getParameters(), FunctionParameter::getName); } }
private static boolean matches(RelDataTypeFactory typeFactory, Function member, List<RelDataType> argumentTypes) { List<FunctionParameter> parameters = member.getParameters(); if (parameters.size() != argumentTypes.size()) { return false; } for (int i = 0; i < argumentTypes.size(); i++) { RelDataType argumentType = argumentTypes.get(i); FunctionParameter parameter = parameters.get(i); if (!canConvert(argumentType, parameter.getType(typeFactory))) { return false; } } return true; }
/** * Return a view macro that may or may not be defined in a certain schema. If it's not defined, returns null. * * @param schemaPlus schema * @param functionName function name * * @return view, or null */ @Nullable private static TableMacro getView(final SchemaPlus schemaPlus, final String functionName) { // Look for a zero-arg function that is also a TableMacro. The returned value // is never null so we don't need to check for that. final Collection<org.apache.calcite.schema.Function> functions = schemaPlus.getFunctions(functionName); for (org.apache.calcite.schema.Function function : functions) { if (function.getParameters().isEmpty() && function instanceof TableMacro) { return (TableMacro) function; } } return null; }
private static boolean matches(RelDataTypeFactory typeFactory, Function member, List<RelDataType> argumentTypes) { List<FunctionParameter> parameters = member.getParameters(); if (parameters.size() != argumentTypes.size()) { return false; } for (int i = 0; i < argumentTypes.size(); i++) { RelDataType argumentType = argumentTypes.get(i); FunctionParameter parameter = parameters.get(i); if (!canConvert(argumentType, parameter.getType(typeFactory))) { return false; } } return true; }
protected TableEntry getImplicitTableBasedOnNullaryFunction(String tableName, boolean caseSensitive) { Collection<Function> functions = schema.getFunctions(tableName); if (functions != null) { for (Function function : functions) { if (function instanceof TableMacro && function.getParameters().isEmpty()) { final Table table = ((TableMacro) function).apply(ImmutableList.of()); return tableEntry(tableName, table); } } } return null; }
protected TableEntry getImplicitTableBasedOnNullaryFunction(String tableName, boolean caseSensitive) { Collection<Function> functions = schema.getFunctions(tableName); if (functions != null) { for (Function function : functions) { if (function instanceof TableMacro && function.getParameters().isEmpty()) { final Table table = ((TableMacro) function).apply(ImmutableList.of()); return tableEntry(tableName, table); } } } return null; }
private FunctionEntry add(String name, Function function) { final FunctionEntryImpl entry = new FunctionEntryImpl(this, name, function); functionMap.put(name, entry); functionNames.add(name); if (function.getParameters().isEmpty()) { nullaryFunctionMap.put(name, entry); } return entry; }
/** Returns a tables derived from explicit and implicit functions * that take zero parameters. */ public final TableEntry getTableBasedOnNullaryFunction(String tableName, boolean caseSensitive) { for (Map.Entry<String, FunctionEntry> entry : nullaryFunctionMap.range(tableName, caseSensitive).entrySet()) { final Function function = entry.getValue().getFunction(); if (function instanceof TableMacro) { assert function.getParameters().isEmpty(); final Table table = ((TableMacro) function).apply(ImmutableList.of()); return tableEntry(tableName, table); } } return getImplicitTableBasedOnNullaryFunction(tableName, caseSensitive); }
/** Returns a tables derived from explicit and implicit functions * that take zero parameters. */ public final TableEntry getTableBasedOnNullaryFunction(String tableName, boolean caseSensitive) { for (Map.Entry<String, FunctionEntry> entry : nullaryFunctionMap.range(tableName, caseSensitive).entrySet()) { final Function function = entry.getValue().getFunction(); if (function instanceof TableMacro) { assert function.getParameters().isEmpty(); final Table table = ((TableMacro) function).apply(ImmutableList.of()); return tableEntry(tableName, table); } } return getImplicitTableBasedOnNullaryFunction(tableName, caseSensitive); }
private FunctionEntry add(String name, Function function) { final FunctionEntryImpl entry = new FunctionEntryImpl(this, name, function); functionMap.put(name, entry); functionNames.add(name); if (function.getParameters().isEmpty()) { nullaryFunctionMap.put(name, entry); } return entry; }
protected TableEntry getImplicitTableBasedOnNullaryFunction(String tableName, boolean caseSensitive) { final long now = System.currentTimeMillis(); final NameSet set = implicitFunctionCache.get(now); for (String s : set.range(tableName, caseSensitive)) { for (Function function : schema.getFunctions(s)) { if (function instanceof TableMacro && function.getParameters().isEmpty()) { final Table table = ((TableMacro) function).apply(ImmutableList.of()); return tableEntry(tableName, table); } } } return null; }
protected TableEntry getImplicitTableBasedOnNullaryFunction(String tableName, boolean caseSensitive) { final long now = System.currentTimeMillis(); final NameSet set = implicitFunctionCache.get(now); for (String s : set.range(tableName, caseSensitive)) { for (Function function : schema.getFunctions(s)) { if (function instanceof TableMacro && function.getParameters().isEmpty()) { final Table table = ((TableMacro) function).apply(ImmutableList.of()); return tableEntry(tableName, table); } } } return null; }
/** Returns tables derived from explicit and implicit functions * that take zero parameters. */ public final NavigableMap<String, Table> getTablesBasedOnNullaryFunctions() { ImmutableSortedMap.Builder<String, Table> builder = new ImmutableSortedMap.Builder<>(NameSet.COMPARATOR); for (Map.Entry<String, FunctionEntry> entry : nullaryFunctionMap.map().entrySet()) { final Function function = entry.getValue().getFunction(); if (function instanceof TableMacro) { assert function.getParameters().isEmpty(); final Table table = ((TableMacro) function).apply(ImmutableList.of()); builder.put(entry.getKey(), table); } } // add tables derived from implicit functions addImplicitTablesBasedOnNullaryFunctionsToBuilder(builder); return builder.build(); }
/** Returns tables derived from explicit and implicit functions * that take zero parameters. */ public final NavigableMap<String, Table> getTablesBasedOnNullaryFunctions() { ImmutableSortedMap.Builder<String, Table> builder = new ImmutableSortedMap.Builder<>(NameSet.COMPARATOR); for (Map.Entry<String, FunctionEntry> entry : nullaryFunctionMap.map().entrySet()) { final Function function = entry.getValue().getFunction(); if (function instanceof TableMacro) { assert function.getParameters().isEmpty(); final Table table = ((TableMacro) function).apply(ImmutableList.of()); builder.put(entry.getKey(), table); } } // add tables derived from implicit functions addImplicitTablesBasedOnNullaryFunctionsToBuilder(builder); return builder.build(); }
protected void addImplicitTablesBasedOnNullaryFunctionsToBuilder( ImmutableSortedMap.Builder<String, Table> builder) { ImmutableSortedMap<String, Table> explicitTables = builder.build(); for (String s : schema.getFunctionNames()) { // explicit table wins. if (explicitTables.containsKey(s)) { continue; } for (Function function : schema.getFunctions(s)) { if (function instanceof TableMacro && function.getParameters().isEmpty()) { final Table table = ((TableMacro) function).apply(ImmutableList.of()); builder.put(s, table); } } } }
protected void addImplicitTablesBasedOnNullaryFunctionsToBuilder( ImmutableSortedMap.Builder<String, Table> builder) { ImmutableSortedMap<String, Table> explicitTables = builder.build(); final long now = System.currentTimeMillis(); final NameSet set = implicitFunctionCache.get(now); for (String s : set.iterable()) { // explicit table wins. if (explicitTables.containsKey(s)) { continue; } for (Function function : schema.getFunctions(s)) { if (function instanceof TableMacro && function.getParameters().isEmpty()) { final Table table = ((TableMacro) function).apply(ImmutableList.of()); builder.put(s, table); } } } }
protected void addImplicitTablesBasedOnNullaryFunctionsToBuilder( ImmutableSortedMap.Builder<String, Table> builder) { ImmutableSortedMap<String, Table> explicitTables = builder.build(); final long now = System.currentTimeMillis(); final NameSet set = implicitFunctionCache.get(now); for (String s : set.iterable()) { // explicit table wins. if (explicitTables.containsKey(s)) { continue; } for (Function function : schema.getFunctions(s)) { if (function instanceof TableMacro && function.getParameters().isEmpty()) { final Table table = ((TableMacro) function).apply(ImmutableList.of()); builder.put(s, table); } } } }
protected void addImplicitTablesBasedOnNullaryFunctionsToBuilder( ImmutableSortedMap.Builder<String, Table> builder) { ImmutableSortedMap<String, Table> explicitTables = builder.build(); for (String s : schema.getFunctionNames()) { // explicit table wins. if (explicitTables.containsKey(s)) { continue; } for (Function function : schema.getFunctions(s)) { if (function instanceof TableMacro && function.getParameters().isEmpty()) { final Table table = ((TableMacro) function).apply(ImmutableList.of()); builder.put(s, table); } } } }