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

Java AbstractSchema类代码示例

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

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



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

示例1: makePostProcessor

import org.apache.calcite.schema.impl.AbstractSchema; //导入依赖的package包/类
/**
 * Creates the post processor routine to be applied against a Connection.
 *
 * <p>Table schema is based on JdbcTest#Employee
 * (refer to {@link JdbcFrontLinqBackTest#mutable}).
 *
 * @param initialData records to be presented in table
 * @return a connection post-processor
 */
private static CalciteAssert.ConnectionPostProcessor makePostProcessor(
    final List<JdbcTest.Employee> initialData) {
  return new CalciteAssert.ConnectionPostProcessor() {
    public Connection apply(final Connection connection)
        throws SQLException {
      CalciteConnection calciteConnection =
          connection.unwrap(CalciteConnection.class);
      SchemaPlus rootSchema = calciteConnection.getRootSchema();
      SchemaPlus mapSchema = rootSchema.add("foo", new AbstractSchema());
      final String tableName = "bar";
      final JdbcTest.AbstractModifiableTable table =
          mutable(tableName, initialData);
      mapSchema.add(tableName, table);
      return calciteConnection;
    }
  };
}
 
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:JdbcFrontLinqBackTest.java


示例2: getRootSchema

import org.apache.calcite.schema.impl.AbstractSchema; //导入依赖的package包/类
private SchemaPlus getRootSchema() throws MetadataStorageManagerException {
    if (rootSchema != null) {
        return rootSchema;
    }
    final SchemaPlus _rootSchema = Frameworks.createRootSchema(true);
    for (String tableSpace : manager.getLocalTableSpaces()) {
        TableSpaceManager tableSpaceManager = manager.getTableSpaceManager(tableSpace);
        SchemaPlus schema = _rootSchema.add(tableSpace, new AbstractSchema());
        List<Table> tables = tableSpaceManager.getAllTablesForPlanner();
        for (Table table : tables) {
            AbstractTableManager tableManager = tableSpaceManager.getTableManager(table.name);
            TableImpl tableDef = new TableImpl(tableManager);
            schema.add(table.name, tableDef);
        }
    }
    rootSchema = _rootSchema;
    return _rootSchema;
}
 
开发者ID:diennea,项目名称:herddb,代码行数:19,代码来源:CalcitePlanner.java


示例3: checkMazeTableFunction

import org.apache.calcite.schema.impl.AbstractSchema; //导入依赖的package包/类
public void checkMazeTableFunction(Boolean solution, String maze)
    throws SQLException, ClassNotFoundException {
  Connection connection = DriverManager.getConnection("jdbc:calcite:");
  CalciteConnection calciteConnection =
      connection.unwrap(CalciteConnection.class);
  SchemaPlus rootSchema = calciteConnection.getRootSchema();
  SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
  final TableFunction table = TableFunctionImpl.create(MAZE_METHOD);
  schema.add("Maze", table);
  final TableFunction table2 = TableFunctionImpl.create(SOLVE_METHOD);
  schema.add("Solve", table2);
  final String sql;
  if (solution) {
    sql = "select *\n"
        + "from table(\"s\".\"Solve\"(5, 3, 1)) as t(s)";
  } else {
    sql = "select *\n"
        + "from table(\"s\".\"Maze\"(5, 3, 1)) as t(s)";
  }
  ResultSet resultSet = connection.createStatement().executeQuery(sql);
  final StringBuilder b = new StringBuilder();
  while (resultSet.next()) {
    b.append(resultSet.getString(1)).append("\n");
  }
  assertThat(b.toString(), is(maze));
}
 
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:ExampleFunctionTest.java


示例4: testUpdate

import org.apache.calcite.schema.impl.AbstractSchema; //导入依赖的package包/类
/** Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-2039">[CALCITE-2039]
 * AssertionError when pushing project to ProjectableFilterableTable</a>
 * using UPDATE via {@link Frameworks}. */
@Test public void testUpdate() throws Exception {
  Table table = new TableImpl();
  final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
  SchemaPlus schema = rootSchema.add("x", new AbstractSchema());
  schema.add("MYTABLE", table);
  List<RelTraitDef> traitDefs = new ArrayList<>();
  traitDefs.add(ConventionTraitDef.INSTANCE);
  traitDefs.add(RelDistributionTraitDef.INSTANCE);
  SqlParser.Config parserConfig =
      SqlParser.configBuilder(SqlParser.Config.DEFAULT)
          .setCaseSensitive(false)
          .build();

  final FrameworkConfig config = Frameworks.newConfigBuilder()
      .parserConfig(parserConfig)
      .defaultSchema(schema)
      .traitDefs(traitDefs)
      // define the rules you want to apply
      .ruleSets(
          RuleSets.ofList(AbstractConverter.ExpandConversionRule.INSTANCE))
      .programs(Programs.ofRules(Programs.RULE_SET))
      .build();
  executeQuery(config, " UPDATE MYTABLE set id=7 where id=1",
      CalcitePrepareImpl.DEBUG);
}
 
开发者ID:apache,项目名称:calcite,代码行数:30,代码来源:FrameworksTest.java


示例5: adviseSql

import org.apache.calcite.schema.impl.AbstractSchema; //导入依赖的package包/类
private void adviseSql(String sql, Function<ResultSet, Void> checker)
    throws ClassNotFoundException, SQLException {
  Properties info = new Properties();
  info.put("lex", "JAVA");
  info.put("quoting", "DOUBLE_QUOTE");
  Connection connection =
      DriverManager.getConnection("jdbc:calcite:", info);
  CalciteConnection calciteConnection =
      connection.unwrap(CalciteConnection.class);
  SchemaPlus rootSchema = calciteConnection.getRootSchema();
  rootSchema.add("hr", new ReflectiveSchema(new HrSchema()));
  SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
  calciteConnection.setSchema("hr");
  final TableFunction table =
      new SqlAdvisorGetHintsFunction();
  schema.add("get_hints", table);
  PreparedStatement ps = connection.prepareStatement("select *\n"
      + "from table(\"s\".\"get_hints\"(?, ?)) as t(id, names, type)");
  SqlParserUtil.StringAndPos sap = SqlParserUtil.findPos(sql);
  ps.setString(1, sap.sql);
  ps.setInt(2, sap.cursor);
  final ResultSet resultSet = ps.executeQuery();
  checker.apply(resultSet);
  resultSet.close();
  connection.close();
}
 
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:JdbcTest.java


示例6: testTableMacro

import org.apache.calcite.schema.impl.AbstractSchema; //导入依赖的package包/类
/**
 * Tests a relation that is accessed via method syntax.
 *
 * <p>The function ({@link Smalls#view(String)} has a return type
 * {@link Table} and the actual returned value implements
 * {@link org.apache.calcite.schema.TranslatableTable}.
 */
@Test public void testTableMacro()
    throws SQLException, ClassNotFoundException {
  Connection connection =
      DriverManager.getConnection("jdbc:calcite:");
  CalciteConnection calciteConnection =
      connection.unwrap(CalciteConnection.class);
  SchemaPlus rootSchema = calciteConnection.getRootSchema();
  SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
  final TableMacro tableMacro = TableMacroImpl.create(Smalls.VIEW_METHOD);
  schema.add("View", tableMacro);
  ResultSet resultSet = connection.createStatement().executeQuery("select *\n"
      + "from table(\"s\".\"View\"('(10), (20)')) as t(n)\n"
      + "where n < 15");
  // The call to "View('(10), (2)')" expands to 'values (1), (3), (10), (20)'.
  assertThat(CalciteAssert.toString(resultSet),
      equalTo("N=1\n"
          + "N=3\n"
          + "N=10\n"));
  connection.close();
}
 
开发者ID:apache,项目名称:calcite,代码行数:28,代码来源:JdbcTest.java


示例7: testTableMacroMap

import org.apache.calcite.schema.impl.AbstractSchema; //导入依赖的package包/类
/** Table macro that takes a MAP as a parameter.
 *
 * <p>Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-588">[CALCITE-588]
 * Allow TableMacro to consume Maps and Collections</a>. */
@Test public void testTableMacroMap()
    throws SQLException, ClassNotFoundException {
  Connection connection =
      DriverManager.getConnection("jdbc:calcite:");
  CalciteConnection calciteConnection =
      connection.unwrap(CalciteConnection.class);
  SchemaPlus rootSchema = calciteConnection.getRootSchema();
  SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
  final TableMacro tableMacro = TableMacroImpl.create(Smalls.STR_METHOD);
  schema.add("Str", tableMacro);
  ResultSet resultSet = connection.createStatement().executeQuery("select *\n"
      + "from table(\"s\".\"Str\"(MAP['a', 1, 'baz', 2],\n"
      + "                         ARRAY[3, 4, CAST(null AS INTEGER)])) as t(n)");
  // The call to "View('(10), (2)')" expands to 'values (1), (3), (10), (20)'.
  assertThat(CalciteAssert.toString(resultSet),
      equalTo("N={'a'=1, 'baz'=2}\n"
          + "N=[3, 4, null]    \n"));
  connection.close();
}
 
开发者ID:apache,项目名称:calcite,代码行数:25,代码来源:JdbcTest.java


示例8: testExplicitImplicitSchemaSameName

import org.apache.calcite.schema.impl.AbstractSchema; //导入依赖的package包/类
@Test public void testExplicitImplicitSchemaSameName() throws Exception {
  final SchemaPlus rootSchema = CalciteSchema.createRootSchema(false).plus();

  // create schema "/a"
  final Map<String, Schema> aSubSchemaMap = new HashMap<>();
  final SchemaPlus aSchema = rootSchema.add("a",
      new AbstractSchema() {
        @Override protected Map<String, Schema> getSubSchemaMap() {
          return aSubSchemaMap;
        }
      });

  // add explicit schema "/a/b".
  aSchema.add("b", new AbstractSchema());

  // add implicit schema "/a/b"
  aSubSchemaMap.put("b", new AbstractSchema());

  aSchema.setCacheEnabled(true);

  // explicit should win implicit.
  assertThat(aSchema.getSubSchemaNames().size(), is(1));
}
 
开发者ID:apache,项目名称:calcite,代码行数:24,代码来源:JdbcTest.java


示例9: testSimpleCalciteSchema

import org.apache.calcite.schema.impl.AbstractSchema; //导入依赖的package包/类
@Test public void testSimpleCalciteSchema() throws Exception {
  final SchemaPlus rootSchema = CalciteSchema.createRootSchema(false, false).plus();

  // create schema "/a"
  final Map<String, Schema> aSubSchemaMap = new HashMap<>();
  final SchemaPlus aSchema = rootSchema.add("a",
      new AbstractSchema() {
        @Override protected Map<String, Schema> getSubSchemaMap() {
          return aSubSchemaMap;
        }
      });

  // add explicit schema "/a/b".
  aSchema.add("b", new AbstractSchema());

  // add implicit schema "/a/c"
  aSubSchemaMap.put("c", new AbstractSchema());

  assertThat(aSchema.getSubSchema("c"), notNullValue());
  assertThat(aSchema.getSubSchema("b"), notNullValue());

  // add implicit schema "/a/b"
  aSubSchemaMap.put("b", new AbstractSchema());
  // explicit should win implicit.
  assertThat(aSchema.getSubSchemaNames().size(), is(2));
}
 
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:JdbcTest.java


示例10: testTableFunction

import org.apache.calcite.schema.impl.AbstractSchema; //导入依赖的package包/类
/**
 * Tests a table function with literal arguments.
 */
@Test public void testTableFunction()
    throws SQLException, ClassNotFoundException {
  Connection connection =
      DriverManager.getConnection("jdbc:calcite:");
  CalciteConnection calciteConnection =
      connection.unwrap(CalciteConnection.class);
  SchemaPlus rootSchema = calciteConnection.getRootSchema();
  SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
  final TableFunction table =
      TableFunctionImpl.create(Smalls.GENERATE_STRINGS_METHOD);
  schema.add("GenerateStrings", table);
  ResultSet resultSet = connection.createStatement().executeQuery("select *\n"
      + "from table(\"s\".\"GenerateStrings\"(5)) as t(n, c)\n"
      + "where char_length(c) > 3");
  assertThat(CalciteAssert.toString(resultSet),
      equalTo("N=4; C=abcd\n"));
}
 
开发者ID:apache,项目名称:calcite,代码行数:21,代码来源:TableFunctionTest.java


示例11: testScannableTableFunction

import org.apache.calcite.schema.impl.AbstractSchema; //导入依赖的package包/类
/**
 * Tests a table function that implements {@link ScannableTable} and returns
 * a single column.
 */
@Test public void testScannableTableFunction()
    throws SQLException, ClassNotFoundException {
  Connection connection = DriverManager.getConnection("jdbc:calcite:");
  CalciteConnection calciteConnection =
      connection.unwrap(CalciteConnection.class);
  SchemaPlus rootSchema = calciteConnection.getRootSchema();
  SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
  final TableFunction table = TableFunctionImpl.create(Smalls.MAZE_METHOD);
  schema.add("Maze", table);
  final String sql = "select *\n"
      + "from table(\"s\".\"Maze\"(5, 3, 1))";
  ResultSet resultSet = connection.createStatement().executeQuery(sql);
  final String result = "S=abcde\n"
      + "S=xyz\n"
      + "S=generate(w=5, h=3, s=1)\n";
  assertThat(CalciteAssert.toString(resultSet), is(result));
}
 
开发者ID:apache,项目名称:calcite,代码行数:22,代码来源:TableFunctionTest.java


示例12: testOperator

import org.apache.calcite.schema.impl.AbstractSchema; //导入依赖的package包/类
/**
 * Tests a relation that is accessed via method syntax.
 * The function returns a {@link org.apache.calcite.linq4j.Queryable}.
 */
@Ignore
@Test public void testOperator() throws SQLException, ClassNotFoundException {
  Connection connection =
      DriverManager.getConnection("jdbc:calcite:");
  CalciteConnection calciteConnection =
      connection.unwrap(CalciteConnection.class);
  SchemaPlus rootSchema = calciteConnection.getRootSchema();
  SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
  schema.add("GenerateStrings",
      TableMacroImpl.create(Smalls.GENERATE_STRINGS_METHOD));
  schema.add("StringUnion",
      TableMacroImpl.create(Smalls.STRING_UNION_METHOD));
  rootSchema.add("hr", new ReflectiveSchema(new JdbcTest.HrSchema()));
  ResultSet resultSet = connection.createStatement().executeQuery(
      "select *\n"
      + "from table(s.StringUnion(\n"
      + "  GenerateStrings(5),\n"
      + "  cursor (select name from emps)))\n"
      + "where char_length(s) > 3");
  assertTrue(resultSet.next());
}
 
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:ReflectiveSchemaTest.java


示例13: testView

import org.apache.calcite.schema.impl.AbstractSchema; //导入依赖的package包/类
/**
 * Tests a view.
 */
@Test public void testView() throws SQLException, ClassNotFoundException {
  Connection connection =
      DriverManager.getConnection("jdbc:calcite:");
  CalciteConnection calciteConnection =
      connection.unwrap(CalciteConnection.class);
  SchemaPlus rootSchema = calciteConnection.getRootSchema();
  SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
  schema.add("emps_view",
      ViewTable.viewMacro(schema,
          "select * from \"hr\".\"emps\" where \"deptno\" = 10",
          null, Arrays.asList("s", "emps_view"), null));
  rootSchema.add("hr", new ReflectiveSchema(new JdbcTest.HrSchema()));
  ResultSet resultSet = connection.createStatement().executeQuery(
      "select *\n"
      + "from \"s\".\"emps_view\"\n"
      + "where \"empid\" < 120");
  assertEquals(
      "empid=100; deptno=10; name=Bill; salary=10000.0; commission=1000\n"
      + "empid=110; deptno=10; name=Theodore; salary=11500.0; commission=250\n",
      CalciteAssert.toString(resultSet));
}
 
开发者ID:apache,项目名称:calcite,代码行数:25,代码来源:ReflectiveSchemaTest.java


示例14: execute

import org.apache.calcite.schema.impl.AbstractSchema; //导入依赖的package包/类
public void execute(CalcitePrepare.Context context) {
  final Pair<CalciteSchema, String> pair =
      SqlDdlNodes.schema(context, true, name);
  final SchemaPlus subSchema0 = pair.left.plus().getSubSchema(pair.right);
  if (subSchema0 != null) {
    if (!getReplace() && !ifNotExists) {
      throw SqlUtil.newContextException(name.getParserPosition(),
          RESOURCE.schemaExists(pair.right));
    }
  }
  final Schema subSchema = new AbstractSchema();
  pair.left.add(pair.right, subSchema);
}
 
开发者ID:apache,项目名称:calcite,代码行数:14,代码来源:SqlCreateSchema.java


示例15: visit

import org.apache.calcite.schema.impl.AbstractSchema; //导入依赖的package包/类
public void visit(JsonMapSchema jsonSchema) {
  checkRequiredAttributes(jsonSchema, "name");
  final SchemaPlus parentSchema = currentMutableSchema("schema");
  final SchemaPlus schema =
      parentSchema.add(jsonSchema.name, new AbstractSchema());
  if (jsonSchema.path != null) {
    schema.setPath(stringListList(jsonSchema.path));
  }
  populateSchema(jsonSchema, schema);
}
 
开发者ID:apache,项目名称:calcite,代码行数:11,代码来源:ModelHandler.java


示例16: testSimpleCalciteSchemaWithView

import org.apache.calcite.schema.impl.AbstractSchema; //导入依赖的package包/类
@Test public void testSimpleCalciteSchemaWithView() throws Exception {
  final SchemaPlus rootSchema = CalciteSchema.createRootSchema(false, false).plus();

  final Multimap<String, org.apache.calcite.schema.Function> functionMap =
      LinkedListMultimap.create();
  // create schema "/a"
  final SchemaPlus aSchema = rootSchema.add("a",
      new AbstractSchema() {
        @Override protected Multimap<String, org.apache.calcite.schema.Function>
        getFunctionMultimap() {
          return functionMap;
        }
      });
  // add view definition
  final String viewName = "V";
  final org.apache.calcite.schema.Function view =
      ViewTable.viewMacro(rootSchema.getSubSchema("a"),
          "values('1', '2')", null, null, false);
  functionMap.put(viewName, view);

  final CalciteSchema calciteSchema = CalciteSchema.from(aSchema);
  assertThat(
      calciteSchema.getTableBasedOnNullaryFunction(viewName, true), notNullValue());
  assertThat(
      calciteSchema.getTableBasedOnNullaryFunction(viewName, false), notNullValue());
  assertThat(
      calciteSchema.getTableBasedOnNullaryFunction("V1", true), nullValue());
  assertThat(
      calciteSchema.getTableBasedOnNullaryFunction("V1", false), nullValue());

  assertThat(calciteSchema.getFunctions(viewName, true), hasItem(view));
  assertThat(calciteSchema.getFunctions(viewName, false), hasItem(view));
  assertThat(calciteSchema.getFunctions("V1", true), not(hasItem(view)));
  assertThat(calciteSchema.getFunctions("V1", false), not(hasItem(view)));
}
 
开发者ID:apache,项目名称:calcite,代码行数:36,代码来源:JdbcTest.java


示例17: testScannableTableFunctionWithNamedParameters

import org.apache.calcite.schema.impl.AbstractSchema; //导入依赖的package包/类
/** As {@link #testScannableTableFunction()} but with named parameters. */
@Test public void testScannableTableFunctionWithNamedParameters()
    throws SQLException, ClassNotFoundException {
  Connection connection = DriverManager.getConnection("jdbc:calcite:");
  CalciteConnection calciteConnection =
      connection.unwrap(CalciteConnection.class);
  SchemaPlus rootSchema = calciteConnection.getRootSchema();
  SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
  final TableFunction table = TableFunctionImpl.create(Smalls.MAZE2_METHOD);
  schema.add("Maze", table);
  final String sql = "select *\n"
      + "from table(\"s\".\"Maze\"(5, 3, 1))";
  final Statement statement = connection.createStatement();
  ResultSet resultSet = statement.executeQuery(sql);
  final String result = "S=abcde\n"
      + "S=xyz\n";
  assertThat(CalciteAssert.toString(resultSet),
      is(result + "S=generate2(w=5, h=3, s=1)\n"));

  final String sql2 = "select *\n"
      + "from table(\"s\".\"Maze\"(WIDTH => 5, HEIGHT => 3, SEED => 1))";
  resultSet = statement.executeQuery(sql2);
  assertThat(CalciteAssert.toString(resultSet),
      is(result + "S=generate2(w=5, h=3, s=1)\n"));

  final String sql3 = "select *\n"
      + "from table(\"s\".\"Maze\"(HEIGHT => 3, WIDTH => 5))";
  resultSet = statement.executeQuery(sql3);
  assertThat(CalciteAssert.toString(resultSet),
      is(result + "S=generate2(w=5, h=3, s=null)\n"));
  connection.close();
}
 
开发者ID:apache,项目名称:calcite,代码行数:33,代码来源:TableFunctionTest.java


示例18: getConnectionWithMultiplyFunction

import org.apache.calcite.schema.impl.AbstractSchema; //导入依赖的package包/类
private Connection getConnectionWithMultiplyFunction()
    throws ClassNotFoundException, SQLException {
  Connection connection =
      DriverManager.getConnection("jdbc:calcite:");
  CalciteConnection calciteConnection =
      connection.unwrap(CalciteConnection.class);
  SchemaPlus rootSchema = calciteConnection.getRootSchema();
  SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
  final TableFunction table =
      TableFunctionImpl.create(Smalls.MULTIPLICATION_TABLE_METHOD);
  schema.add("multiplication", table);
  return connection;
}
 
开发者ID:apache,项目名称:calcite,代码行数:14,代码来源:TableFunctionTest.java


示例19: testViewPath

import org.apache.calcite.schema.impl.AbstractSchema; //导入依赖的package包/类
/**
 * Tests a view with a path.
 */
@Test public void testViewPath() throws SQLException, ClassNotFoundException {
  Connection connection =
      DriverManager.getConnection("jdbc:calcite:");
  CalciteConnection calciteConnection =
      connection.unwrap(CalciteConnection.class);
  SchemaPlus rootSchema = calciteConnection.getRootSchema();
  SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
  // create a view s.emps based on hr.emps. uses explicit schema path "hr".
  schema.add("emps",
      ViewTable.viewMacro(schema,
          "select * from \"emps\" where \"deptno\" = 10",
          ImmutableList.of("hr"), ImmutableList.of("s", "emps"), null));
  schema.add("hr_emps",
      ViewTable.viewMacro(schema,
          "select * from \"emps\"",
          ImmutableList.of("hr"), ImmutableList.of("s", "hr_emps"), null));
  schema.add("s_emps",
      ViewTable.viewMacro(schema,
          "select * from \"emps\"",
          ImmutableList.of("s"), ImmutableList.of("s", "s_emps"), null));
  schema.add("null_emps",
      ViewTable.viewMacro(schema, "select * from \"emps\"", null,
          ImmutableList.of("s", "null_emps"), null));
  rootSchema.add("hr", new ReflectiveSchema(new JdbcTest.HrSchema()));
  final Statement statement = connection.createStatement();
  ResultSet resultSet;
  resultSet = statement.executeQuery(
      "select * from \"s\".\"hr_emps\"");
  assertEquals(4, count(resultSet)); // "hr_emps" -> "hr"."emps", 4 rows
  resultSet = statement.executeQuery(
      "select * from \"s\".\"s_emps\""); // "s_emps" -> "s"."emps", 3 rows
  assertEquals(3, count(resultSet));
  resultSet = statement.executeQuery(
      "select * from \"s\".\"null_emps\""); // "null_emps" -> "s"."emps", 3
  assertEquals(3, count(resultSet));
  statement.close();
}
 
开发者ID:apache,项目名称:calcite,代码行数:41,代码来源:ReflectiveSchemaTest.java


示例20: testUserDefinedFunctionInView

import org.apache.calcite.schema.impl.AbstractSchema; //导入依赖的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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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