use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Function in project sidewinder by srotya.
the class SqlApi method initCalcite.
public void initCalcite() throws SQLException, ClassNotFoundException {
Class.forName("org.apache.calcite.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:calcite:");
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
ModelHandler.create(calciteConnection.getRootSchema(), "now", Arrays.asList(""), NowFunction.class.getName(), "apply");
ModelHandler.create(calciteConnection.getRootSchema(), "milli", Arrays.asList(""), ToMilliseconds.class.getName(), "apply");
ModelHandler.create(calciteConnection.getRootSchema(), "ts", Arrays.asList(""), ToTimestamp.class.getName(), "eval");
ModelHandler.create(calciteConnection.getRootSchema(), "datediff", Arrays.asList(""), DateDiffFunction.class.getName(), "apply");
for (Function function : calciteConnection.getRootSchema().getFunctions("ts")) {
System.out.println(function.getParameters().get(0).getName());
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Function in project calcite by apache.
the class CachingCalciteSchema method addImplicitFunctionsToBuilder.
protected void addImplicitFunctionsToBuilder(ImmutableList.Builder<Function> builder, String name, boolean caseSensitive) {
// Add implicit functions, case-insensitive.
final long now = System.currentTimeMillis();
final NameSet set = implicitFunctionCache.get(now);
for (String name2 : set.range(name, caseSensitive)) {
final Collection<Function> functions = schema.getFunctions(name2);
if (functions != null) {
builder.addAll(functions);
}
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Function in project calcite by apache.
the class SimpleCalciteSchema method addImplicitTablesBasedOnNullaryFunctionsToBuilder.
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);
}
}
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Function in project calcite by apache.
the class CalciteCatalogReader method operatorTable.
/**
* Creates an operator table that contains functions in the given class.
*
* @see ModelHandler#addFunctions
*/
public static SqlOperatorTable operatorTable(String className) {
// Dummy schema to collect the functions
final CalciteSchema schema = CalciteSchema.createRootSchema(false, false);
ModelHandler.addFunctions(schema.plus(), null, ImmutableList.<String>of(), className, "*", true);
// The following is technical debt; see [CALCITE-2082] Remove
// RelDataTypeFactory argument from SqlUserDefinedAggFunction constructor
final SqlTypeFactoryImpl typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
final ListSqlOperatorTable table = new ListSqlOperatorTable();
for (String name : schema.getFunctionNames()) {
for (Function function : schema.getFunctions(name, true)) {
final SqlIdentifier id = new SqlIdentifier(name, SqlParserPos.ZERO);
table.add(toOp(typeFactory, id, function));
}
}
return table;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Function in project streamline by hortonworks.
the class StreamlineSqlImpl method handleCreateFunction.
private void handleCreateFunction(SqlCreateFunction sqlCreateFunction) throws ClassNotFoundException {
if (sqlCreateFunction.jarName() != null) {
throw new UnsupportedOperationException("UDF 'USING JAR' not implemented");
}
Method method;
Function function;
if ((method = findMethod(sqlCreateFunction.className(), "evaluate")) != null) {
function = ScalarFunctionImpl.create(method);
} else if (findMethod(sqlCreateFunction.className(), "add") != null) {
function = AggregateFunctionImpl.create(Class.forName(sqlCreateFunction.className()));
} else {
throw new RuntimeException("Invalid scalar or aggregate function");
}
schema.add(sqlCreateFunction.functionName().toUpperCase(), function);
hasUdf = true;
}
Aggregations