• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ScalarFunctionImpl类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.calcite.schema.impl.ScalarFunctionImpl的典型用法代码示例。如果您正苦于以下问题:Java ScalarFunctionImpl类的具体用法?Java ScalarFunctionImpl怎么用?Java ScalarFunctionImpl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ScalarFunctionImpl类属于org.apache.calcite.schema.impl包,在下文中一共展示了ScalarFunctionImpl类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: handleCreateFunction

import org.apache.calcite.schema.impl.ScalarFunctionImpl; //导入依赖的package包/类
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;
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:17,代码来源:StreamlineSqlImpl.java


示例2: apply

import org.apache.calcite.schema.impl.ScalarFunctionImpl; //导入依赖的package包/类
@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);
}
 
开发者ID:vlsi,项目名称:mat-calcite-plugin,代码行数:18,代码来源:ClassRowTypeCache.java


示例3: getSnapshot

import org.apache.calcite.schema.impl.ScalarFunctionImpl; //导入依赖的package包/类
@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;
}
 
开发者ID:vlsi,项目名称:mat-calcite-plugin,代码行数:18,代码来源:ExecutionRexBuilderContext.java


示例4: getIObject

import org.apache.calcite.schema.impl.ScalarFunctionImpl; //导入依赖的package包/类
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;
}
 
开发者ID:vlsi,项目名称:mat-calcite-plugin,代码行数:18,代码来源:RexBuilderContext.java


示例5: SamzaSqlScalarFunctionImpl

import org.apache.calcite.schema.impl.ScalarFunctionImpl; //导入依赖的package包/类
public SamzaSqlScalarFunctionImpl(String udfName, Method udfMethod) {
  myIncFunction = ScalarFunctionImpl.create(udfMethod);
  this.udfName = udfName;
  this.udfMethod = udfMethod;
  this.getUdfMethod = Arrays.stream(SamzaSqlExecutionContext.class.getMethods())
      .filter(x -> x.getName().equals("getOrCreateUdf"))
      .findFirst()
      .get();
}
 
开发者ID:apache,项目名称:samza,代码行数:10,代码来源:SamzaSqlScalarFunctionImpl.java


示例6: sqlOverDummyTable

import org.apache.calcite.schema.impl.ScalarFunctionImpl; //导入依赖的package包/类
public static CalciteState sqlOverDummyTable(String sql)
        throws RelConversionException, ValidationException, SqlParseException {
    SchemaPlus schema = Frameworks.createRootSchema(true);
    JavaTypeFactory typeFactory = new JavaTypeFactoryImpl
            (RelDataTypeSystem.DEFAULT);
    StreamableTable streamableTable = new CompilerUtil.TableBuilderInfo(typeFactory)
            .field("ID", SqlTypeName.INTEGER)
            .field("NAME", typeFactory.createType(String.class))
            .field("ADDR", typeFactory.createType(String.class))
            .build();
    Table table = streamableTable.stream();
    schema.add("FOO", table);
    schema.add("BAR", table);
    schema.add("MYPLUS", ScalarFunctionImpl.create(MyPlus.class, "eval"));

    List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>();
    sqlOperatorTables.add(SqlStdOperatorTable.instance());
    sqlOperatorTables.add(new CalciteCatalogReader(CalciteSchema.from(schema),
            false,
            Collections.<String>emptyList(), typeFactory));
    SqlOperatorTable chainedSqlOperatorTable = new ChainedSqlOperatorTable(sqlOperatorTables);
    FrameworkConfig config = Frameworks.newConfigBuilder().defaultSchema(
            schema).operatorTable(chainedSqlOperatorTable).build();
    Planner planner = Frameworks.getPlanner(config);
    SqlNode parse = planner.parse(sql);
    SqlNode validate = planner.validate(parse);
    RelNode tree = planner.convert(validate);
    System.out.println(RelOptUtil.toString(tree, SqlExplainLevel.ALL_ATTRIBUTES));
    return new CalciteState(schema, tree);
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:31,代码来源:TestCompilerUtils.java


示例7: infer

import org.apache.calcite.schema.impl.ScalarFunctionImpl; //导入依赖的package包/类
private static SqlReturnTypeInference infer(final ScalarFunction function) {
  return new SqlReturnTypeInference() {
    public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
      final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
      final RelDataType type;
      if (function instanceof ScalarFunctionImpl) {
        type = ((ScalarFunctionImpl) function).getReturnType(typeFactory,
            opBinding);
      } else {
        type = function.getReturnType(typeFactory);
      }
      return toSql(typeFactory, type);
    }
  };
}
 
开发者ID:apache,项目名称:calcite,代码行数:16,代码来源:CalciteCatalogReader.java


示例8: testUserDefinedFunctionInView

import org.apache.calcite.schema.impl.ScalarFunctionImpl; //导入依赖的package包/类
/** Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-937">[CALCITE-937]
 * User-defined function within view</a>. */
@Test public void testUserDefinedFunctionInView() throws Exception {
  Class.forName("org.apache.calcite.jdbc.Driver");
  Connection connection = DriverManager.getConnection("jdbc:calcite:");
  CalciteConnection calciteConnection =
      connection.unwrap(CalciteConnection.class);
  SchemaPlus rootSchema = calciteConnection.getRootSchema();
  rootSchema.add("hr", new ReflectiveSchema(new JdbcTest.HrSchema()));

  SchemaPlus post = rootSchema.add("POST", new AbstractSchema());
  post.add("MY_INCREMENT",
      ScalarFunctionImpl.create(Smalls.MyIncrement.class, "eval"));

  final String viewSql = "select \"empid\" as EMPLOYEE_ID,\n"
      + "  \"name\" || ' ' || \"name\" as EMPLOYEE_NAME,\n"
      + "  \"salary\" as EMPLOYEE_SALARY,\n"
      + "  POST.MY_INCREMENT(\"empid\", 10) as INCREMENTED_SALARY\n"
      + "from \"hr\".\"emps\"";
  post.add("V_EMP",
      ViewTable.viewMacro(post, viewSql, ImmutableList.<String>of(),
          ImmutableList.of("POST", "V_EMP"), null));

  final String result = ""
      + "EMPLOYEE_ID=100; EMPLOYEE_NAME=Bill Bill; EMPLOYEE_SALARY=10000.0; INCREMENTED_SALARY=110.0\n"
      + "EMPLOYEE_ID=200; EMPLOYEE_NAME=Eric Eric; EMPLOYEE_SALARY=8000.0; INCREMENTED_SALARY=220.0\n"
      + "EMPLOYEE_ID=150; EMPLOYEE_NAME=Sebastian Sebastian; EMPLOYEE_SALARY=7000.0; INCREMENTED_SALARY=165.0\n"
      + "EMPLOYEE_ID=110; EMPLOYEE_NAME=Theodore Theodore; EMPLOYEE_SALARY=11500.0; INCREMENTED_SALARY=121.0\n";

  Statement statement = connection.createStatement();
  ResultSet resultSet = statement.executeQuery(viewSql);
  assertThat(CalciteAssert.toString(resultSet), is(result));
  resultSet.close();

  ResultSet viewResultSet =
      statement.executeQuery("select * from \"POST\".\"V_EMP\"");
  assertThat(CalciteAssert.toString(viewResultSet), is(result));
  statement.close();
  connection.close();
}
 
开发者ID:apache,项目名称:calcite,代码行数:42,代码来源:UdfTest.java


示例9: registerUdf

import org.apache.calcite.schema.impl.ScalarFunctionImpl; //导入依赖的package包/类
/**
 * Register a UDF function which can be used in SQL expression.
 */
public void registerUdf(String functionName, Class<? extends BeamSqlUdf> clazz) {
  schema.add(functionName, ScalarFunctionImpl.create(clazz, BeamSqlUdf.UDF_METHOD));
}
 
开发者ID:apache,项目名称:beam,代码行数:7,代码来源:BeamSqlEnv.java


示例10: sqlOverNestedTable

import org.apache.calcite.schema.impl.ScalarFunctionImpl; //导入依赖的package包/类
public static CalciteState sqlOverNestedTable(String sql)
        throws RelConversionException, ValidationException, SqlParseException {
    SchemaPlus schema = Frameworks.createRootSchema(true);
    JavaTypeFactory typeFactory = new JavaTypeFactoryImpl
            (RelDataTypeSystem.DEFAULT);

    StreamableTable streamableTable = new CompilerUtil.TableBuilderInfo(typeFactory)
            .field("ID", SqlTypeName.INTEGER)
            .field("MAPFIELD",
                    typeFactory.createTypeWithNullability(
                            typeFactory.createMapType(
                                    typeFactory.createTypeWithNullability(
                                            typeFactory.createSqlType(SqlTypeName.VARCHAR), true),
                                    typeFactory.createTypeWithNullability(
                                            typeFactory.createSqlType(SqlTypeName.INTEGER), true))
                            , true))
            .field("NESTEDMAPFIELD",
                    typeFactory.createTypeWithNullability(
                        typeFactory.createMapType(
                                typeFactory.createTypeWithNullability(
                                        typeFactory.createSqlType(SqlTypeName.VARCHAR), true),
                                typeFactory.createTypeWithNullability(
                                        typeFactory.createMapType(
                                                typeFactory.createTypeWithNullability(
                                                        typeFactory.createSqlType(SqlTypeName.VARCHAR), true),
                                                typeFactory.createTypeWithNullability(
                                                        typeFactory.createSqlType(SqlTypeName.INTEGER), true))
                                        , true))
                                    , true))
            .field("ARRAYFIELD", typeFactory.createTypeWithNullability(
                    typeFactory.createArrayType(
                        typeFactory.createTypeWithNullability(
                            typeFactory.createSqlType(SqlTypeName.INTEGER), true), -1L)
                    , true))
            .build();
    Table table = streamableTable.stream();
    schema.add("FOO", table);
    schema.add("BAR", table);
    schema.add("MYPLUS", ScalarFunctionImpl.create(MyPlus.class, "eval"));
    List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>();
    sqlOperatorTables.add(SqlStdOperatorTable.instance());
    sqlOperatorTables.add(new CalciteCatalogReader(CalciteSchema.from(schema),
                                                   false,
                                                   Collections.<String>emptyList(), typeFactory));
    SqlOperatorTable chainedSqlOperatorTable = new ChainedSqlOperatorTable(sqlOperatorTables);
    FrameworkConfig config = Frameworks.newConfigBuilder().defaultSchema(
            schema).operatorTable(chainedSqlOperatorTable).build();
    Planner planner = Frameworks.getPlanner(config);
    SqlNode parse = planner.parse(sql);
    SqlNode validate = planner.validate(parse);
    RelNode tree = planner.convert(validate);
    System.out.println(RelOptUtil.toString(tree, SqlExplainLevel.ALL_ATTRIBUTES));
    return new CalciteState(schema, tree);
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:55,代码来源:TestCompilerUtils.java


示例11: resolveSchema

import org.apache.calcite.schema.impl.ScalarFunctionImpl; //导入依赖的package包/类
public static PackageSchema resolveSchema(ISnapshot snapshot) {

        try {
            // Create functions for schema
            ImmutableMultimap.Builder<String, Function> builder = ImmutableMultimap.builder();
            builder.putAll(ScalarFunctionImpl.createAll(HeapFunctions.class));
            builder.putAll(TableFunctions.createAll());
            builder.putAll(SnapshotFunctions.createAll(snapshot));
            builder.put("getHints", new SqlAdvisorGetHintsFunction());
            ImmutableMultimap<String, Function> functions = builder.build();

            // Create default schema
            PackageSchema defaultSchema = new PackageSchema(functions);

            // Collect all classes names
            Collection<IClass> classes = snapshot.getClasses();
            HashSet<String> classesNames = new HashSet<>();
            for (IClass iClass : classes) {
                classesNames.add(iClass.getName());
            }

            PackageSchema instanceOfPackage = defaultSchema.getPackage("instanceof");

            // Add all classes to schema
            for (String fullClassName : classesNames) {
                IClassesList classOnly = new IClassesList(snapshot, fullClassName, false);

                // Make class available via "package.name.ClassName" (full class name in a root schema)
                defaultSchema.addClass(fullClassName, classOnly);

                String simpleClassName = getClassName(fullClassName);

                // Make class available via package.name.ClassName (schema.schema.Class)
                PackageSchema packageSchema = getPackage(defaultSchema, fullClassName);
                packageSchema.addClass(simpleClassName, classOnly);

                // Add instanceof
                IClassesList withSubClasses = new IClassesList(snapshot, fullClassName, true);

                // Make class available via "instanceof.package.name.ClassName"
                defaultSchema.addClass("instanceof." + fullClassName, withSubClasses);

                // Make class available via instanceof.package.name.ClassName
                PackageSchema instanceOfSchema = getPackage(instanceOfPackage, fullClassName);
                instanceOfSchema.addClass(simpleClassName, withSubClasses);

            }

            // Add thread stacks table
            defaultSchema.getPackage("heap").addClass("ThreadStackFrames", new SnapshotThreadStacksTable(snapshot));

            return defaultSchema;
        } catch (SnapshotException e) {
            throw new RuntimeException("Cannot resolve package schemes", e);
        }
    }
 
开发者ID:vlsi,项目名称:mat-calcite-plugin,代码行数:57,代码来源:PackageSchema.java


示例12: registerFunction

import org.apache.calcite.schema.impl.ScalarFunctionImpl; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:16,代码来源:SQLExecEnvironment.java



注:本文中的org.apache.calcite.schema.impl.ScalarFunctionImpl类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MutablePrincipalCollection类代码示例发布时间:2022-05-23
下一篇:
Java Mac类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap