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

Java Hook类代码示例

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

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



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

示例1: testRewriting

import org.apache.calcite.runtime.Hook; //导入依赖的package包/类
@Test
public void testRewriting() {
	CalciteAssert
			.model(TargetDatabase.makeJournalledModel(versionType))
			.query("DELETE FROM \"" + virtualSchemaName + "\".\"depts\" WHERE \"deptno\"=3")
			.withHook(Hook.PROGRAM, JournalledJdbcRuleManager.program())
			.explainContains("PLAN=JdbcToEnumerableConverter\n" +
					"  JdbcTableModify(table=[[" + virtualSchemaName + ", depts_journal]], operation=[INSERT], flattened=[false])\n" +
					"    JdbcProject(deptno=[$0], department_name=[$1], version_number=[CURRENT_TIMESTAMP], subsequent_version_number=[CURRENT_TIMESTAMP])\n" +
					"      JdbcFilter(condition=[AND(=($2, $4), IS NULL($3), =($0, 3))])\n" +
					"        JdbcProject(deptno=[$0], department_name=[$1], version_number=[$2], subsequent_version_number=[$3], $f4=[MAX($2) OVER (PARTITION BY $0 ORDER BY $2 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)])\n" +
					"          JdbcTableScan(table=[[" + virtualSchemaName + ", depts_journal]])\n")
			.planUpdateHasSql("INSERT INTO \"" + actualSchemaName + "\".\"depts_journal\" (\"deptno\", \"department_name\", \"version_number\", \"subsequent_version_number\")\n" +
					"(SELECT \"deptno\", \"department_name\", CURRENT_TIMESTAMP AS \"version_number\", CURRENT_TIMESTAMP AS \"subsequent_version_number\"\n" +
					"FROM (SELECT \"deptno\", \"department_name\", \"version_number\", \"subsequent_version_number\", MAX(\"version_number\") OVER (PARTITION BY \"deptno\" ORDER BY \"version_number\" ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS \"$f4\"\n" +
					"FROM \"" + actualSchemaName + "\".\"depts_journal\") AS \"t\"\n" +
					"WHERE \"version_number\" = \"$f4\" AND \"subsequent_version_number\" IS NULL AND \"deptno\" = 3)", 1);
}
 
开发者ID:tzolov,项目名称:calcite-sql-rewriter,代码行数:19,代码来源:DeleteTimestampIntegrationTest.java


示例2: testRewritingWrongVersionType

import org.apache.calcite.runtime.Hook; //导入依赖的package包/类
@Test(expected = RuntimeException.class)
public void testRewritingWrongVersionType() {
	CalciteAssert
			.model(TargetDatabase.makeJournalledModel(versionType).replace("TIMESTAMP", "BIGINT"))
			.query("DELETE FROM \"" + virtualSchemaName + "\".\"depts\" WHERE \"deptno\"=3")
			.withHook(Hook.PROGRAM, JournalledJdbcRuleManager.program())
			.explainContains("PLAN=JdbcToEnumerableConverter\n" +
					"  JdbcTableModify(table=[[" + virtualSchemaName + ", depts_journal]], operation=[INSERT], flattened=[false])\n" +
					"    JdbcProject(deptno=[$0], department_name=[$1], version_number=[CURRENT_TIMESTAMP], subsequent_version_number=[CURRENT_TIMESTAMP])\n" +
					"      JdbcFilter(condition=[AND(=($2, $4), IS NULL($3), =($0, 3))])\n" +
					"        JdbcProject(deptno=[$0], department_name=[$1], version_number=[$2], subsequent_version_number=[$3], $f4=[MAX($2) OVER (PARTITION BY $0 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)])\n" +
					"          JdbcTableScan(table=[[" + virtualSchemaName + ", depts_journal]])\n")
			.planUpdateHasSql("INSERT INTO \"" + actualSchemaName + "\".\"depts_journal\" (\"deptno\", \"department_name\", \"version_number\", \"subsequent_version_number\")\n" +
					"(SELECT \"deptno\", \"department_name\", CURRENT_TIMESTAMP AS \"version_number\", CURRENT_TIMESTAMP AS \"subsequent_version_number\"\n" +
					"FROM (SELECT \"deptno\", \"department_name\", \"version_number\", \"subsequent_version_number\", MAX(\"version_number\") OVER (PARTITION BY \"deptno\" ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS \"$f4\"\n" +
					"FROM \"" + actualSchemaName + "\".\"depts_journal\") AS \"t\"\n" +
					"WHERE \"version_number\" = \"$f4\" AND \"subsequent_version_number\" IS NULL AND \"deptno\" = 3)", 1);
}
 
开发者ID:tzolov,项目名称:calcite-sql-rewriter,代码行数:19,代码来源:DeleteTimestampIntegrationTest.java


示例3: testRewriting

import org.apache.calcite.runtime.Hook; //导入依赖的package包/类
@Test
public void testRewriting() {
	CalciteAssert
			.model(TargetDatabase.makeJournalledModel(versionType))
			.query("SELECT \"empid\" FROM \"" + virtualSchemaName + "\".\"emps\"")
			.withHook(Hook.PROGRAM, JournalledJdbcRuleManager.program())
			.explainContains("PLAN=JdbcToEnumerableConverter\n" +
					"  JdbcProject(empid=[$0])\n" +
					"    JdbcFilter(condition=[AND(=($1, $3), IS NULL($2))])\n" +
					"      JdbcProject(empid=[$0], version_number=[$2], subsequent_version_number=[$3], $f6=[MAX($2) OVER (PARTITION BY $0 ORDER BY $2 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)])\n" +
					"        JdbcTableScan(table=[[" + virtualSchemaName + ", emps_journal]])\n")
			.planHasSql("SELECT \"empid\"\n" +
					"FROM (SELECT \"empid\", \"version_number\", \"subsequent_version_number\", MAX(\"version_number\") OVER (PARTITION BY \"empid\" ORDER BY \"version_number\" ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS \"$f6\"\n" +
					"FROM \"" + actualSchemaName + "\".\"emps_journal\") AS \"t\"\n" +
					"WHERE \"version_number\" = \"$f6\" AND \"subsequent_version_number\" IS NULL")
			.returns("empid=1\n" +
					"empid=2\n" +
					"empid=3\n" +
					"empid=4\n" +
					"empid=6\n");
}
 
开发者ID:tzolov,项目名称:calcite-sql-rewriter,代码行数:22,代码来源:SelectIntegrationTest.java


示例4: testRewriting

import org.apache.calcite.runtime.Hook; //导入依赖的package包/类
@Test
public void testRewriting() {
	CalciteAssert
			.model(TargetDatabase.makeJournalledModel(versionType))
			.query("UPDATE \"" + virtualSchemaName + "\".\"depts\" SET \"department_name\"='First' WHERE \"deptno\" = 3")
			.withHook(Hook.PROGRAM, JournalledJdbcRuleManager.program())
			.explainContains("PLAN=JdbcToEnumerableConverter\n" +
					"  JdbcTableModify(table=[[" + virtualSchemaName + ", depts_journal]], operation=[INSERT], flattened=[false])\n" +
					"    JdbcProject(deptno=[$0], department_name=['First'])\n" +
					"      JdbcFilter(condition=[AND(=($1, $3), IS NULL($2), =($0, 3))])\n" +
					"        JdbcProject(deptno=[$0], version_number=[$2], subsequent_version_number=[$3], $f4=[MAX($2) OVER (PARTITION BY $0 ORDER BY $2 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)])\n" +
					"          JdbcTableScan(table=[[" + virtualSchemaName + ", depts_journal]])\n")
			.planUpdateHasSql("INSERT INTO \"" + actualSchemaName + "\".\"depts_journal\" (\"deptno\", \"department_name\")\n" +
					"(SELECT \"deptno\", 'First' AS \"department_name\"\n" +
					"FROM (SELECT \"deptno\", \"version_number\", \"subsequent_version_number\", MAX(\"version_number\") OVER (PARTITION BY \"deptno\" ORDER BY \"version_number\" ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS \"$f4\"\n" +
					"FROM \"" + actualSchemaName + "\".\"depts_journal\") AS \"t\"\n" +
					"WHERE \"version_number\" = \"$f4\" AND \"subsequent_version_number\" IS NULL AND \"deptno\" = 3)", 1);
}
 
开发者ID:tzolov,项目名称:calcite-sql-rewriter,代码行数:19,代码来源:UpdateTimestampIntegrationTest.java


示例5: testRewritingWithIncorrectVersionType

import org.apache.calcite.runtime.Hook; //导入依赖的package包/类
@Test(expected = RuntimeException.class)
public void testRewritingWithIncorrectVersionType() {
	CalciteAssert
			.model(TargetDatabase.makeJournalledModel(versionType).replace("TIMESTAMP", "BIGINT"))
			.query("UPDATE \"" + virtualSchemaName + "\".\"depts\" SET \"department_name\"='First' WHERE \"deptno\" = 3")
			.withHook(Hook.PROGRAM, JournalledJdbcRuleManager.program())
			.explainContains("PLAN=JdbcToEnumerableConverter\n" +
					"  JdbcTableModify(table=[[" + virtualSchemaName + ", depts_journal]], operation=[INSERT], flattened=[false])\n" +
					"    JdbcProject(deptno=[$0], department_name=['First'])\n" +
					"      JdbcFilter(condition=[AND(=($1, $3), IS NULL($2), =($0, 3))])\n" +
					"        JdbcProject(deptno=[$0], version_number=[$2], subsequent_version_number=[$3], $f4=[MAX($2) OVER (PARTITION BY $0 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)])\n" +
					"          JdbcTableScan(table=[[" + virtualSchemaName + ", depts_journal]])\n")
			.planUpdateHasSql("INSERT INTO \"" + actualSchemaName + "\".\"depts_journal\" (\"deptno\", \"department_name\")\n" +
					"(SELECT \"deptno\", 'First' AS \"department_name\"\n" +
					"FROM (SELECT \"deptno\", \"version_number\", \"subsequent_version_number\", MAX(\"version_number\") OVER (PARTITION BY \"deptno\" ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS \"$f4\"\n" +
					"FROM \"" + actualSchemaName + "\".\"depts_journal\") AS \"t\"\n" +
					"WHERE \"version_number\" = \"$f4\" AND \"subsequent_version_number\" IS NULL AND \"deptno\" = 3)", 1);
}
 
开发者ID:tzolov,项目名称:calcite-sql-rewriter,代码行数:19,代码来源:UpdateTimestampIntegrationTest.java


示例6: testFactoryWillAutomaticallyAddRules

import org.apache.calcite.runtime.Hook; //导入依赖的package包/类
@Test
public void testFactoryWillAutomaticallyAddRules() {
	// This test changes the global state of Calcite! It shouldn't cause issues elsewhere since the rules avoid
	// changing unrecognised tables, so will not apply to their own output.
	JournalledJdbcSchema.Factory.INSTANCE.setAutomaticallyAddRules(true);
	JournalledJdbcSchema.Factory.INSTANCE.create(null, "my-parent", options);
	try {
		Program def = Mockito.mock(Program.class);
		Holder<Program> holder = Holder.of(def);
		Hook.PROGRAM.run(holder);
		Assert.assertTrue(holder.get() instanceof SequenceProgram);
		Assert.assertTrue(((SequenceProgram) holder.get()).getPrograms().get(0) instanceof ForcedRulesProgram);
	} finally {
		// ensure no gap where another hook may be added
		JournalledJdbcSchema.Factory.INSTANCE.setAutomaticallyAddRules(false);
		JournalledJdbcRuleManager.removeHook();
	}
}
 
开发者ID:tzolov,项目名称:calcite-sql-rewriter,代码行数:19,代码来源:JournalledJdbcSchemaTest.java


示例7: testRejectsConflictingID

import org.apache.calcite.runtime.Hook; //导入依赖的package包/类
@Test
public void testRejectsConflictingID() {
	Assume.assumeTrue("Unique ID enforcement not currently supported for TIMESTAMP", versionType != JournalVersionType.TIMESTAMP);
	try {
		CalciteAssert
				.model(TargetDatabase.makeJournalledModel(versionType))
				.query("INSERT INTO \"" + virtualSchemaName + "\".\"emps\" (\"empid\", \"deptno\", \"last_name\") VALUES (2, 1, 'Me')")
				.withHook(Hook.PROGRAM, JournalledJdbcRuleManager.program())
				.updates(0);
		Assert.fail("Expected duplicate key exception");
	} catch(RuntimeException e) {
		// Look for an error about "duplicate key" and consider it a success. For everything else, it's a fail.
		boolean foundDuplicateError = false;
		Throwable ex = e;
		while (ex != null) {
			if (ex.getMessage().contains("duplicate key")) {
				foundDuplicateError = true;
				break;
			}
			ex = ex.getCause();
		}
		if (!foundDuplicateError) {
			throw e;
		}
	}
}
 
开发者ID:tzolov,项目名称:calcite-sql-rewriter,代码行数:27,代码来源:InsertIntegrationTest.java


示例8: testInsertSelect

import org.apache.calcite.runtime.Hook; //导入依赖的package包/类
@Test
public void testInsertSelect() {
	CalciteAssert
			.model(TargetDatabase.makeJournalledModel(versionType))
			.query("INSERT INTO \"" + virtualSchemaName + "\".\"emps\" (\"empid\", \"last_name\", \"deptno\") SELECT \"deptno\" + 1000, 'added', \"deptno\" FROM \"" + virtualSchemaName + "\".\"depts\"")
			.withHook(Hook.PROGRAM, JournalledJdbcRuleManager.program())
			.explainContains("PLAN=JdbcToEnumerableConverter\n" +
					"  JdbcTableModify(table=[[" + virtualSchemaName + ", emps_journal]], operation=[INSERT], flattened=[false])\n" +
					"    JdbcProject(empid=[+($0, 1000)], deptno=[$0], last_name=['added'])\n" +
					"      JdbcFilter(condition=[AND(=($1, $3), IS NULL($2))])\n" +
					"        JdbcProject(deptno=[$0], version_number=[$2], subsequent_version_number=[$3], $f4=[MAX($2) OVER (PARTITION BY $0 ORDER BY $2 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)])\n" +
					"          JdbcTableScan(table=[[" + virtualSchemaName + ", depts_journal]])\n")
			.planUpdateHasSql("INSERT INTO \"" + actualSchemaName + "\".\"emps_journal\" (\"empid\", \"deptno\", \"last_name\")\n" +
					"(SELECT \"deptno\" + 1000 AS \"empid\", \"deptno\", 'added' AS \"last_name\"\n" +
					"FROM (SELECT \"deptno\", \"version_number\", \"subsequent_version_number\", MAX(\"version_number\") OVER (PARTITION BY \"deptno\" ORDER BY \"version_number\" ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS \"$f4\"\n" +
					"FROM \"" + actualSchemaName + "\".\"depts_journal\") AS \"t\"\n" +
					"WHERE \"version_number\" = \"$f4\" AND \"subsequent_version_number\" IS NULL)", 4);
}
 
开发者ID:tzolov,项目名称:calcite-sql-rewriter,代码行数:19,代码来源:InsertIntegrationTest.java


示例9: StreamlineDataContext

import org.apache.calcite.runtime.Hook; //导入依赖的package包/类
public StreamlineDataContext() {
    // Store the time at which the query started executing. The SQL
    // standard says that functions such as CURRENT_TIMESTAMP return the
    // same value throughout the query.

    final Holder<Long> timeHolder = Holder.of(System.currentTimeMillis());

    // Give a hook chance to alter the clock.
    Hook.CURRENT_TIME.run(timeHolder);
    final long time = timeHolder.get();
    final TimeZone timeZone = Calendar.getInstance().getTimeZone();
    final long localOffset = timeZone.getOffset(time);
    final long currentOffset = localOffset;

    ImmutableMap.Builder<Object, Object> builder = ImmutableMap.builder();
    builder.put(Variable.UTC_TIMESTAMP.camelName, time)
            .put(Variable.CURRENT_TIMESTAMP.camelName, time + currentOffset)
            .put(Variable.LOCAL_TIMESTAMP.camelName, time + localOffset)
            .put(Variable.TIME_ZONE.camelName, timeZone);
    map = builder.build();
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:22,代码来源:StreamlineDataContext.java


示例10: testStdin

import org.apache.calcite.runtime.Hook; //导入依赖的package包/类
@Test public void testStdin() throws SQLException {
  try (Hook.Closeable ignore = Hook.STANDARD_STREAMS.addThread(
      new Function<Holder<Object[]>, Void>() {
        public Void apply(Holder<Object[]> o) {
          final Object[] values = o.get();
          final InputStream in = (InputStream) values[0];
          final String s = "First line\n"
              + "Second line";
          final ByteArrayInputStream in2 =
              new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8));
          final OutputStream out = (OutputStream) values[1];
          final OutputStream err = (OutputStream) values[2];
          o.set(new Object[] {in2, out, err});
          return null;
        }
      })) {
    assertThat(foo("select count(*) as c from stdin"), is("2\n"));
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:20,代码来源:OsAdapterTest.java


示例11: testLocalTimeFunc

import org.apache.calcite.runtime.Hook; //导入依赖的package包/类
@Test public void testLocalTimeFunc() {
  tester.setFor(SqlStdOperatorTable.LOCALTIME);
  tester.checkScalar("LOCALTIME", TIME_PATTERN, "TIME(0) NOT NULL");
  tester.checkFails(
      "^LOCALTIME()^",
      "No match found for function signature LOCALTIME\\(\\)",
      false);
  tester.checkScalar(
      "LOCALTIME(1)", TIME_PATTERN,
      "TIME(1) NOT NULL");

  final Pair<String, Hook.Closeable> pair = currentTimeString(LOCAL_TZ);
  tester.checkScalar(
      "CAST(LOCALTIME AS VARCHAR(30))",
      Pattern.compile(
          pair.left.substring(11) + "[0-9][0-9]:[0-9][0-9]"),
      "VARCHAR(30) NOT NULL");
  tester.checkScalar(
      "LOCALTIME",
      Pattern.compile(
          pair.left.substring(11) + "[0-9][0-9]:[0-9][0-9]"),
      "TIME(0) NOT NULL");
  pair.right.close();
}
 
开发者ID:apache,项目名称:calcite,代码行数:25,代码来源:SqlOperatorBaseTest.java


示例12: testCurrentTimeFunc

import org.apache.calcite.runtime.Hook; //导入依赖的package包/类
@Test public void testCurrentTimeFunc() {
  tester.setFor(SqlStdOperatorTable.CURRENT_TIME);
  tester.checkScalar(
      "CURRENT_TIME", TIME_PATTERN,
      "TIME(0) NOT NULL");
  tester.checkFails(
      "^CURRENT_TIME()^",
      "No match found for function signature CURRENT_TIME\\(\\)",
      false);
  tester.checkScalar(
      "CURRENT_TIME(1)", TIME_PATTERN, "TIME(1) NOT NULL");

  final Pair<String, Hook.Closeable> pair = currentTimeString(CURRENT_TZ);
  tester.checkScalar(
      "CAST(CURRENT_TIME AS VARCHAR(30))",
      Pattern.compile(pair.left.substring(11) + "[0-9][0-9]:[0-9][0-9]"),
      "VARCHAR(30) NOT NULL");
  tester.checkScalar(
      "CURRENT_TIME",
      Pattern.compile(pair.left.substring(11) + "[0-9][0-9]:[0-9][0-9]"),
      "TIME(0) NOT NULL");
  pair.right.close();
}
 
开发者ID:apache,项目名称:calcite,代码行数:24,代码来源:SqlOperatorBaseTest.java


示例13: checkThatMaterialize

import org.apache.calcite.runtime.Hook; //导入依赖的package包/类
/** Checks that a given query can use a materialized view with a given
 * definition. */
private CalciteAssert.AssertQuery checkThatMaterialize(String materialize,
    String query, String name, boolean existing, String model,
    Function<ResultSet, Void> explainChecker, final RuleSet rules) {
  try (final TryThreadLocal.Memo ignored = Prepare.THREAD_TRIM.push(true)) {
    MaterializationService.setThreadLocal();
    CalciteAssert.AssertQuery that = CalciteAssert.that()
        .withMaterializations(model, existing, name, materialize)
        .query(query)
        .enableMaterializations(true);

    // Add any additional rules required for the test
    if (rules.iterator().hasNext()) {
      that.withHook(Hook.PLANNER, new Function<RelOptPlanner, Void>() {
        public Void apply(RelOptPlanner planner) {
          for (RelOptRule rule : rules) {
            planner.addRule(rule);
          }
          return null;
        }
      });
    }

    return that.explainMatches("", explainChecker);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:28,代码来源:MaterializationTest.java


示例14: testIntersect

import org.apache.calcite.runtime.Hook; //导入依赖的package包/类
@Test public void testIntersect() {
  final String sql = ""
      + "select \"empid\", \"name\" from \"hr\".\"emps\" where \"deptno\"=10\n"
      + "intersect\n"
      + "select \"empid\", \"name\" from \"hr\".\"emps\" where \"empid\">=150";
  CalciteAssert.hr()
      .query(sql)
      .withHook(Hook.PLANNER, new Function<RelOptPlanner, Void>() {
        @Override public Void apply(RelOptPlanner planner) {
          planner.removeRule(IntersectToDistinctRule.INSTANCE);
          return null;
        }
      })
      .explainContains(""
          + "PLAN=EnumerableIntersect(all=[false])")
      .returnsUnordered("empid=150; name=Sebastian");
}
 
开发者ID:apache,项目名称:calcite,代码行数:18,代码来源:JdbcTest.java


示例15: testHook

import org.apache.calcite.runtime.Hook; //导入依赖的package包/类
/** Tests that {@link Hook#PARSE_TREE} works. */
@Test public void testHook() {
  final int[] callCount = {0};
  try (Hook.Closeable hook = Hook.PARSE_TREE.addThread(
      new Function<Object[], Object>() {
        public Void apply(Object[] args) {
          assertThat(args.length, equalTo(2));
          assertThat(args[0], instanceOf(String.class));
          assertThat((String) args[0],
              equalTo("select \"deptno\", \"commission\", sum(\"salary\") s\n"
                  + "from \"hr\".\"emps\"\n"
                  + "group by \"deptno\", \"commission\""));
          assertThat(args[1], instanceOf(SqlSelect.class));
          ++callCount[0];
          return null;
        }
      })) {
    // Simple query does not run the hook.
    testSimple();
    assertThat(callCount[0], equalTo(0));

    // Non-trivial query runs hook once.
    testGroupByNull();
    assertThat(callCount[0], equalTo(1));
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:JdbcTest.java


示例16: testDialect

import org.apache.calcite.runtime.Hook; //导入依赖的package包/类
/** Tests {@link SqlDialect}. */
@Test public void testDialect() {
  final String[] sqls = {null};
  CalciteAssert.that()
      .with(CalciteAssert.Config.JDBC_FOODMART)
      .query("select count(*) as c from \"foodmart\".\"employee\" as e1\n"
          + "  where \"first_name\" = 'abcde'\n"
          + "  and \"gender\" = 'F'")
      .withHook(Hook.QUERY_PLAN,
          new Function<String, Void>() {
            public Void apply(String sql) {
              sqls[0] = sql;
              return null;
            }
          })
      .returns("C=0\n");
  switch (CalciteAssert.DB) {
  case HSQLDB:
    assertThat(Util.toLinux(sqls[0]),
        equalTo("SELECT COUNT(*) AS \"C\"\n"
            + "FROM \"foodmart\".\"employee\"\n"
            + "WHERE \"first_name\" = 'abcde' AND \"gender\" = 'F'"));
    break;
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:JdbcTest.java


示例17: ensurePlan

import org.apache.calcite.runtime.Hook; //导入依赖的package包/类
private void ensurePlan(Function<Integer, Void> checkUpdate) {
  if (plan != null) {
    return;
  }
  addHook(Hook.JAVA_PLAN,
      new Function<String, Void>() {
        public Void apply(String a0) {
          plan = a0;
          return null;
        }
      });
  try {
    assertQuery(createConnection(), sql, limit, materializationsEnabled,
        hooks, null, checkUpdate, null);
    assertNotNull(plan);
  } catch (Exception e) {
    throw new RuntimeException("exception while executing [" + sql + "]",
        e);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:21,代码来源:CalciteAssert.java


示例18: queryContains

import org.apache.calcite.runtime.Hook; //导入依赖的package包/类
/** Runs the query and applies a checker to the generated third-party
 * queries. The checker should throw to fail the test if it does not see
 * what it wants. This method can be used to check whether a particular
 * MongoDB or SQL query is generated, for instance. */
public AssertQuery queryContains(Function<List, Void> predicate1) {
  final List<Object> list = Lists.newArrayList();
  addHook(Hook.QUERY_PLAN,
      new Function<Object, Void>() {
        public Void apply(Object a0) {
          list.add(a0);
          return null;
        }
      });
  try {
    assertQuery(createConnection(), sql, limit, materializationsEnabled,
        hooks, null, null, null);
    predicate1.apply(list);
    return this;
  } catch (Exception e) {
    throw new RuntimeException(
        "exception while executing [" + sql + "]", e);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:24,代码来源:CalciteAssert.java


示例19: testReduceConstants

import org.apache.calcite.runtime.Hook; //导入依赖的package包/类
@Test public void testReduceConstants() throws Exception {
  HepProgram program = new HepProgramBuilder()
      .addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE)
      .addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE)
      .addRuleInstance(ReduceExpressionsRule.JOIN_INSTANCE)
      .build();

  // NOTE jvs 27-May-2006: among other things, this verifies
  // intentionally different treatment for identical coalesce expression
  // in select and where.

  // There is "CAST(2 AS INTEGER)" in the plan because 2 has type "INTEGER NOT
  // NULL" and we need "INTEGER".
  final String sql = "select"
      + " 1+2, d.deptno+(3+4), (5+6)+d.deptno, cast(null as integer),"
      + " coalesce(2,null), row(7+8)"
      + " from dept d inner join emp e"
      + " on d.deptno = e.deptno + (5-5)"
      + " where d.deptno=(7+8) and d.deptno=(8+7) and d.deptno=coalesce(2,null)";
  sql(sql).with(program)
      .withProperty(Hook.REL_BUILDER_SIMPLIFY, false)
      .check();
}
 
开发者ID:apache,项目名称:calcite,代码行数:24,代码来源:RelOptRulesTest.java


示例20: testRewriting

import org.apache.calcite.runtime.Hook; //导入依赖的package包/类
@Test
public void testRewriting() {
	CalciteAssert
			.model(TargetDatabase.makeJournalledModel(versionType))
			.query("DELETE FROM \"" + virtualSchemaName + "\".\"depts\" WHERE \"deptno\"=3")
			.withHook(Hook.PROGRAM, JournalledJdbcRuleManager.program())
			.planUpdateHasSql("INSERT INTO \"" + actualSchemaName + "\".\"depts_journal\" (\"deptno\", \"department_name\", \"version_number\", \"subsequent_version_number\")\n" +
					"(SELECT \"deptno\", \"department_name\", \"version_number\" + 1 AS \"version_number\", \"version_number\" + 1 AS \"subsequent_version_number\"\n" +
					"FROM (SELECT \"deptno\", \"department_name\", \"version_number\", \"subsequent_version_number\", MAX(\"version_number\") OVER (PARTITION BY \"deptno\" ORDER BY \"version_number\" ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS \"$f4\"\n" +
					"FROM \"" + actualSchemaName + "\".\"depts_journal\") AS \"t\"\n" +
					"WHERE \"version_number\" = \"$f4\" AND \"subsequent_version_number\" IS NULL AND \"deptno\" = 3)", 1);
}
 
开发者ID:tzolov,项目名称:calcite-sql-rewriter,代码行数:13,代码来源:DeleteBigintIntegrationTest.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java GetSplitState类代码示例发布时间:2022-05-23
下一篇:
Java Receiver类代码示例发布时间: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