本文整理了Java中org.apache.calcite.runtime.Hook.run()
方法的一些代码示例,展示了Hook.run()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hook.run()
方法的具体详情如下:
包路径:org.apache.calcite.runtime.Hook
类名称:Hook
方法名:run
[英]Runs all handlers registered for this Hook, with the given argument.
[中]使用给定参数运行为此挂钩注册的所有处理程序。
代码示例来源:origin: apache/storm
/**
* StormDataContext Constructor.
*/
public StormDataContext() {
// 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();
}
代码示例来源:origin: apache/incubator-druid
@SuppressWarnings("unchecked")
private <T> Sequence<T> runQuery(Query<T> query)
{
Hook.QUERY_PLAN.run(query);
final String queryId = UUID.randomUUID().toString();
plannerContext.addNativeQueryId(queryId);
query = query.withId(queryId)
.withSqlQueryId(plannerContext.getSqlQueryId());
final AuthenticationResult authenticationResult = plannerContext.getAuthenticationResult();
return queryLifecycleFactory.factorize().runSimple(query, authenticationResult, null);
}
代码示例来源:origin: hortonworks/streamline
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();
}
代码示例来源:origin: org.apache.storm/storm-sql-runtime
public StormDataContext() {
// 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();
}
代码示例来源:origin: org.apache.calcite/calcite-core
/** Returns the value of a property hook.
* (Property hooks take a {@link Holder} as an argument.) */
public <V> V get(V defaultValue) {
final Holder<V> holder = Holder.of(defaultValue);
run(holder);
return holder.get();
}
代码示例来源:origin: Qihoo360/Quicksql
/** Returns the value of a property hook.
* (Property hooks take a {@link Holder} as an argument.) */
public <V> V get(V defaultValue) {
final Holder<V> holder = Holder.of(defaultValue);
run(holder);
return holder.get();
}
代码示例来源:origin: Qihoo360/Quicksql
DruidQueryNode(Compiler interpreter, DruidQuery query) {
this.query = query;
this.sink = interpreter.sink(query);
this.querySpec = query.getQuerySpec();
Hook.QUERY_PLAN.run(querySpec);
}
代码示例来源:origin: org.apache.calcite/calcite-druid
DruidQueryNode(Compiler interpreter, DruidQuery query) {
this.query = query;
this.sink = interpreter.sink(query);
this.querySpec = query.getQuerySpec();
Hook.QUERY_PLAN.run(querySpec);
}
代码示例来源:origin: Qihoo360/Quicksql
private ElasticsearchJson.Result httpRequest(ObjectNode query) throws IOException {
Objects.requireNonNull(query, "query");
String uri = String.format(Locale.ROOT, "/%s/%s/_search", indexName, typeName);
Hook.QUERY_PLAN.run(query);
final String json = mapper.writeValueAsString(query);
LOGGER.debug("Elasticsearch Query: {}", json);
HttpEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
Response response = restClient.performRequest("POST", uri, Collections.emptyMap(), entity);
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
final String error = EntityUtils.toString(response.getEntity());
final String message = String.format(Locale.ROOT,
"Error while querying Elastic (on %s/%s) status: %s\nQuery:\n%s\nError:\n%s\n",
response.getHost(), response.getRequestLine(), response.getStatusLine(), query, error);
throw new RuntimeException(message);
}
try (InputStream is = response.getEntity().getContent()) {
return mapper.readValue(is, ElasticsearchJson.Result.class);
}
}
代码示例来源:origin: org.apache.calcite/calcite-core
public void reduce(RexBuilder rexBuilder, List<RexNode> constExps,
List<RexNode> reducedValues) {
Object[] values;
try {
values = compiledFunction.apply(dataContext);
assert values.length == constExps.size();
final List<Object> valueList = Arrays.asList(values);
for (Pair<RexNode, Object> value : Pair.zip(constExps, valueList)) {
reducedValues.add(
rexBuilder.makeLiteral(value.right, value.left.getType(), true));
}
} catch (RuntimeException e) {
// One or more of the expressions failed.
// Don't reduce any of the expressions.
reducedValues.addAll(constExps);
values = new Object[constExps.size()];
}
Hook.EXPRESSION_REDUCER.run(Pair.of(code, values));
}
代码示例来源:origin: Qihoo360/Quicksql
public void reduce(RexBuilder rexBuilder, List<RexNode> constExps,
List<RexNode> reducedValues) {
Object[] values;
try {
values = compiledFunction.apply(dataContext);
assert values.length == constExps.size();
final List<Object> valueList = Arrays.asList(values);
for (Pair<RexNode, Object> value : Pair.zip(constExps, valueList)) {
reducedValues.add(
rexBuilder.makeLiteral(value.right, value.left.getType(), true));
}
} catch (RuntimeException e) {
// One or more of the expressions failed.
// Don't reduce any of the expressions.
reducedValues.addAll(constExps);
values = new Object[constExps.size()];
}
Hook.EXPRESSION_REDUCER.run(Pair.of(code, values));
}
代码示例来源:origin: Qihoo360/Quicksql
Hook.CURRENT_TIME.run(timeHolder);
final long time = timeHolder.get();
final TimeZone timeZone = connection.getTimeZone();
Hook.STANDARD_STREAMS.run(streamHolder);
代码示例来源:origin: org.apache.druid/druid-sql
@SuppressWarnings("unchecked")
private <T> Sequence<T> runQuery(final Query<T> query)
{
Hook.QUERY_PLAN.run(query);
final AuthenticationResult authenticationResult = plannerContext.getAuthenticationResult();
return queryLifecycleFactory.factorize().runSimple(query, authenticationResult, null);
}
代码示例来源:origin: org.apache.calcite/calcite-core
protected Program getProgram() {
// Allow a test to override the default program.
final Holder<Program> holder = Holder.of(null);
Hook.PROGRAM.run(holder);
if (holder.get() != null) {
return holder.get();
}
return Programs.standard();
}
代码示例来源:origin: Qihoo360/Quicksql
protected Program getProgram() {
// Allow a test to override the default program.
final Holder<Program> holder = Holder.of(null);
Hook.PROGRAM.run(holder);
if (holder.get() != null) {
return holder.get();
}
return Programs.standard();
}
代码示例来源:origin: Qihoo360/Quicksql
for (Pair<RelNode, List<RelOptMaterialization>> use : materializationUses) {
RelNode rel = use.left;
Hook.SUB.run(rel);
registerImpl(rel, root.set);
if (!latticeUses.isEmpty()) {
RelNode rel = latticeUses.get(0).left;
Hook.SUB.run(rel);
registerImpl(rel, root.set);
代码示例来源:origin: Qihoo360/Quicksql
/** Wraps the SQL string in a
* {@link org.apache.calcite.jdbc.CalcitePrepare.Query} object, giving the
* {@link Hook#STRING_TO_QUERY} hook chance to override. */
private CalcitePrepare.Query<Object> toQuery(
Context context, String sql) {
final Holder<CalcitePrepare.Query<Object>> queryHolder =
Holder.of(CalcitePrepare.Query.of(sql));
final FrameworkConfig config = Frameworks.newConfigBuilder()
.parserConfig(SqlParser.Config.DEFAULT)
.defaultSchema(context.getRootSchema().plus())
.build();
Hook.STRING_TO_QUERY.run(Pair.of(config, queryHolder));
return queryHolder.get();
}
代码示例来源:origin: org.apache.calcite/calcite-core
/** Wraps the SQL string in a
* {@link org.apache.calcite.jdbc.CalcitePrepare.Query} object, giving the
* {@link Hook#STRING_TO_QUERY} hook chance to override. */
private CalcitePrepare.Query<Object> toQuery(
Context context, String sql) {
final Holder<CalcitePrepare.Query<Object>> queryHolder =
Holder.of(CalcitePrepare.Query.of(sql));
final FrameworkConfig config = Frameworks.newConfigBuilder()
.parserConfig(SqlParser.Config.DEFAULT)
.defaultSchema(context.getRootSchema().plus())
.build();
Hook.STRING_TO_QUERY.run(Pair.of(config, queryHolder));
return queryHolder.get();
}
代码示例来源:origin: Qihoo360/Quicksql
public static Bindable toBindable(Map<String, Object> parameters,
CalcitePrepare.SparkHandler spark, EnumerableRel rel,
EnumerableRel.Prefer prefer) {
EnumerableRelImplementor relImplementor =
new EnumerableRelImplementor(rel.getCluster().getRexBuilder(),
parameters);
final ClassDeclaration expr = relImplementor.implementRoot(rel, prefer);
String s = Expressions.toString(expr.memberDeclarations, "\n", false);
if (CalcitePrepareImpl.DEBUG) {
Util.debugCode(System.out, s);
}
Hook.JAVA_PLAN.run(s);
try {
if (spark != null && spark.enabled()) {
return spark.compile(expr, s);
} else {
return getBindable(expr, s, rel.getRowType().getFieldCount());
}
} catch (Exception e) {
throw Helper.INSTANCE.wrap("Error while compiling generated Java code:\n"
+ s, e);
}
}
代码示例来源:origin: org.apache.calcite/calcite-core
public static Bindable toBindable(Map<String, Object> parameters,
CalcitePrepare.SparkHandler spark, EnumerableRel rel,
EnumerableRel.Prefer prefer) {
EnumerableRelImplementor relImplementor =
new EnumerableRelImplementor(rel.getCluster().getRexBuilder(),
parameters);
final ClassDeclaration expr = relImplementor.implementRoot(rel, prefer);
String s = Expressions.toString(expr.memberDeclarations, "\n", false);
if (CalcitePrepareImpl.DEBUG) {
Util.debugCode(System.out, s);
}
Hook.JAVA_PLAN.run(s);
try {
if (spark != null && spark.enabled()) {
return spark.compile(expr, s);
} else {
return getBindable(expr, s, rel.getRowType().getFieldCount());
}
} catch (Exception e) {
throw Helper.INSTANCE.wrap("Error while compiling generated Java code:\n"
+ s, e);
}
}
内容来源于网络,如有侵权,请联系作者删除!