use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Function in project calcite by apache.
the class CachingCalciteSchema method addImplicitTablesBasedOnNullaryFunctionsToBuilder.
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);
}
}
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Function in project calcite by apache.
the class CachingCalciteSchema method getImplicitTableBasedOnNullaryFunction.
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;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Function in project calcite by apache.
the class SqlCreateView method execute.
public void execute(CalcitePrepare.Context context) {
final Pair<CalciteSchema, String> pair = SqlDdlNodes.schema(context, true, name);
final SchemaPlus schemaPlus = pair.left.plus();
for (Function function : schemaPlus.getFunctions(pair.right)) {
if (function.getParameters().isEmpty()) {
if (!getReplace()) {
throw SqlUtil.newContextException(name.getParserPosition(), RESOURCE.viewExists(pair.right));
}
pair.left.removeFunction(pair.right);
}
}
final SqlNode q = SqlDdlNodes.renameColumns(columnList, query);
final String sql = q.toSqlString(CalciteSqlDialect.DEFAULT).getSql();
final ViewTableMacro viewTableMacro = ViewTable.viewMacro(schemaPlus, sql, pair.left.path(null), context.getObjectPath(), false);
final TranslatableTable x = viewTableMacro.apply(ImmutableList.of());
Util.discard(x);
schemaPlus.add(pair.right, viewTableMacro);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Function in project calcite by apache.
the class ReflectiveSchema method createFunctionMap.
private Multimap<String, Function> createFunctionMap() {
final ImmutableMultimap.Builder<String, Function> builder = ImmutableMultimap.builder();
for (Method method : clazz.getMethods()) {
final String methodName = method.getName();
if (method.getDeclaringClass() == Object.class || methodName.equals("toString")) {
continue;
}
if (TranslatableTable.class.isAssignableFrom(method.getReturnType())) {
final TableMacro tableMacro = new MethodTableMacro(this, method);
builder.put(methodName, tableMacro);
}
}
return builder.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Function in project calcite by apache.
the class CalciteCatalogReader method getFunctionsFrom.
private Collection<Function> getFunctionsFrom(List<String> names) {
final List<Function> functions2 = Lists.newArrayList();
final List<List<String>> schemaNameList = new ArrayList<>();
if (names.size() > 1) {
// the last 2 items in the path.
if (schemaPaths.size() > 1) {
schemaNameList.addAll(Util.skip(schemaPaths));
} else {
schemaNameList.addAll(schemaPaths);
}
} else {
for (List<String> schemaPath : schemaPaths) {
CalciteSchema schema = SqlValidatorUtil.getSchema(rootSchema, schemaPath, nameMatcher);
if (schema != null) {
schemaNameList.addAll(schema.getPath());
}
}
}
for (List<String> schemaNames : schemaNameList) {
CalciteSchema schema = SqlValidatorUtil.getSchema(rootSchema, Iterables.concat(schemaNames, Util.skipLast(names)), nameMatcher);
if (schema != null) {
final String name = Util.last(names);
functions2.addAll(schema.getFunctions(name, true));
}
}
return functions2;
}
Aggregations