Java Code Examples for org.apache.calcite.schema.impl.ScalarFunctionImpl#create()
The following examples show how to use
org.apache.calcite.schema.impl.ScalarFunctionImpl#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StreamlineSqlImpl.java From streamline with Apache License 2.0 | 6 votes |
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; }
Example 2
Source File: ClassRowTypeCache.java From mat-calcite-plugin with Apache License 2.0 | 6 votes |
@Override public RexNode apply(RexBuilderContext context) { RelOptCluster cluster = context.getCluster(); RelDataTypeFactory typeFactory = cluster.getTypeFactory(); final SqlFunction UDF = new SqlUserDefinedFunction( new SqlIdentifier("RESOLVE_SIMPLE", SqlParserPos.ZERO), ReturnTypes.explicit(typeFactory.createJavaType(Object.class)), null, OperandTypes.ANY_ANY, ImmutableList.of(typeFactory.createTypeWithNullability(typeFactory.createJavaType(IObject.class), false), typeFactory.createJavaType(int.class)), ScalarFunctionImpl.create(IObjectMethods.class, "resolveSimpleValue")); RexBuilder b = context.getBuilder(); RexNode rexNode = b.makeCall(UDF, context.getIObject(), b.makeLiteral(name)); return b.makeCast(dataType, rexNode); }
Example 3
Source File: ClassRowTypeCache.java From mat-calcite-plugin with Apache License 2.0 | 6 votes |
@Override public RexNode apply(RexBuilderContext context) { RelOptCluster cluster = context.getCluster(); RelDataTypeFactory typeFactory = cluster.getTypeFactory(); final SqlFunction UDF = new SqlUserDefinedFunction( new SqlIdentifier("RESOLVE_REFERENCE", SqlParserPos.ZERO), ReturnTypes.explicit(typeFactory.createJavaType(HeapReference.class)), null, OperandTypes.ANY_ANY, ImmutableList.of(typeFactory.createTypeWithNullability(typeFactory.createJavaType(IObject.class), false), typeFactory.createJavaType(String.class)), ScalarFunctionImpl.create(IObjectMethods.class, "resolveReferenceValue")); RexBuilder b = context.getBuilder(); return b.makeCall(UDF, context.getIObject(), b.makeLiteral(name)); }
Example 4
Source File: ExecutionRexBuilderContext.java From mat-calcite-plugin with Apache License 2.0 | 6 votes |
@Override public RexNode getSnapshot() { if (snapshot == null) { RelDataTypeFactory typeFactory = getCluster().getTypeFactory(); RexBuilder b = getBuilder(); final SqlFunction UDF = new SqlUserDefinedFunction( new SqlIdentifier("GET_SNAPSHOT", SqlParserPos.ZERO), ReturnTypes.explicit(typeFactory.createTypeWithNullability(typeFactory.createJavaType(ISnapshot.class), false)), null, OperandTypes.NUMERIC, ImmutableList.of(typeFactory.createJavaType(Integer.class)), ScalarFunctionImpl.create(SnapshotHolder.class, "get")); snapshot = b.makeCall(UDF, b.makeLiteral(snapshotId, typeFactory.createSqlType(SqlTypeName.INTEGER), false)); } return snapshot; }
Example 5
Source File: RexBuilderContext.java From mat-calcite-plugin with Apache License 2.0 | 6 votes |
public RexNode getIObject() { if (object == null) { RelDataTypeFactory typeFactory = getCluster().getTypeFactory(); RexBuilder b = getBuilder(); final SqlFunction GET_IOBJECT = new SqlUserDefinedFunction( new SqlIdentifier("GET_IOBJECT", SqlParserPos.ZERO), ReturnTypes.explicit(typeFactory.createTypeWithNullability(typeFactory.createJavaType(IObject.class), false)), null, OperandTypes.ANY_ANY, ImmutableList.of(typeFactory.createTypeWithNullability(typeFactory.createJavaType(ISnapshot.class), false), typeFactory.createJavaType(int.class)), ScalarFunctionImpl.create(ISnapshotMethods.class, "getIObject")); object = b.makeCall(GET_IOBJECT, getSnapshot(), getIObjectId()); } return object; }
Example 6
Source File: SamzaSqlScalarFunctionImpl.java From samza with Apache License 2.0 | 5 votes |
public SamzaSqlScalarFunctionImpl(UdfMetadata udfMetadata) { myIncFunction = ScalarFunctionImpl.create(udfMetadata.getUdfMethod()); this.udfMetadata = udfMetadata; this.udfName = udfMetadata.getName(); this.udfMethod = udfMetadata.getUdfMethod(); this.getUdfMethod = Arrays.stream(SamzaSqlExecutionContext.class.getMethods()) .filter(x -> x.getName().equals("getOrCreateUdf")) .findFirst() .get(); }
Example 7
Source File: ClassRowTypeCache.java From mat-calcite-plugin with Apache License 2.0 | 5 votes |
public RexNode apply(RexBuilderContext context) { RelOptCluster cluster = context.getCluster(); RelDataTypeFactory typeFactory = cluster.getTypeFactory(); final SqlFunction UDF = new SqlUserDefinedFunction( new SqlIdentifier("TO_REFERENCE", SqlParserPos.ZERO), ReturnTypes.explicit(typeFactory.createJavaType(HeapReference.class)), null, OperandTypes.ANY, ImmutableList.of(typeFactory.createTypeWithNullability(typeFactory.createJavaType(IObject.class), false)), ScalarFunctionImpl.create(ISnapshotMethods.class, "toReference") ); return context.getBuilder().makeCall(UDF, context.getIObject()); }
Example 8
Source File: SQLExecEnvironment.java From attic-apex-malhar with Apache License 2.0 | 3 votes |
/** * Register custom function from given static method with this {@link SQLExecEnvironment} * * @param name Name of the scalar SQL function that needs make available to SQL Statement * @param clazz {@link Class} which contains given static method * @param methodName Name of the method from given clazz * * @return Return this {@link SQLExecEnvironment} */ public SQLExecEnvironment registerFunction(String name, Class clazz, String methodName) { Preconditions.checkNotNull(name, "Function name cannot be null"); ScalarFunction scalarFunction = ScalarFunctionImpl.create(clazz, methodName); return registerFunction(name, scalarFunction); }