本文整理了Java中org.apache.calcite.util.Util
类的一些代码示例,展示了Util
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util
类的具体详情如下:
包路径:org.apache.calcite.util.Util
类名称:Util
[英]Miscellaneous utility functions.
[中]其他实用功能。
代码示例来源:origin: apache/hive
final String name = nameIterator.hasNext() ? nameIterator.next() : null;
final String name2 = inferAlias(exprList, node);
names.add(Util.first(name, name2));
final RelDataType inputRowType = peek().getRowType();
if (!force && RexUtil.isIdentity(exprList, inputRowType)) {
if (names.equals(inputRowType.getFieldNames())) {
RexUtil.createStructType(cluster.getTypeFactory(), exprList,
names, SqlValidatorUtil.F_SUGGESTER);
stack.push(
new Frame(frame.rel,
ImmutableList.of(Pair.of(frame.right.get(0).left, rowType))));
return this;
projectFactory.createProject(build(), ImmutableList.copyOf(exprList),
names);
push(project);
代码示例来源:origin: apache/drill
public void onMatch(RelOptRuleCall call) {
final Filter filter = call.rel(0);
final Project project = call.rel(1);
final List<RexNode> newProjects = new ArrayList<>(project.getProjects());
newProjects.add(filter.getCondition());
final RelOptCluster cluster = filter.getCluster();
RelDataType newRowType =
cluster.getTypeFactory().builder()
.addAll(project.getRowType().getFieldList())
.add("condition", Util.last(newProjects).getType())
.build();
final RelNode newProject =
project.copy(project.getTraitSet(),
project.getInput(),
newProjects,
newRowType);
final RexInputRef newCondition =
cluster.getRexBuilder().makeInputRef(newProject,
newProjects.size() - 1);
call.transformTo(filter.copy(filter.getTraitSet(), newProject, newCondition));
}
}
代码示例来源:origin: apache/hive
private ImmutableList<RexNode> getValidPreds(RelOptCluster cluster, RelNode child,
Set<String> predicatesToExclude, List<RexNode> rexs, RelDataType rType) {
InputRefValidator validator = new InputRefValidator(rType.getFieldList());
List<RexNode> valids = new ArrayList<RexNode>(rexs.size());
for (RexNode rex : rexs) {
try {
rex.accept(validator);
valids.add(rex);
} catch (Util.FoundOne e) {
Util.swallow(e, null);
}
}
// We need to filter i) those that have been pushed already as stored in the join,
// and ii) those that were already in the subtree rooted at child
ImmutableList<RexNode> toPush = HiveCalciteUtil.getPredsNotPushedAlready(predicatesToExclude,
child, valids);
return toPush;
}
代码示例来源:origin: apache/flink
public SqlNode validate(SqlNode topNode) {
SqlValidatorScope scope = new EmptyScope(this);
scope = new CatalogScope(scope, ImmutableList.of("CATALOG"));
final SqlNode topNode2 = validateScopedExpression(topNode, scope);
final RelDataType type = getValidatedNodeType(topNode2);
Util.discard(type);
return topNode2;
}
代码示例来源:origin: org.apache.calcite/calcite-core
/** Creates a call that concatenates patterns;
* for use in {@link #match}. */
public RexNode patternConcat(Iterable<? extends RexNode> nodes) {
final ImmutableList<RexNode> list = ImmutableList.copyOf(nodes);
if (list.size() > 2) {
// Convert into binary calls
return patternConcat(patternConcat(Util.skipLast(list)), Util.last(list));
}
final RelDataType t = getTypeFactory().createSqlType(SqlTypeName.NULL);
return getRexBuilder().makeCall(t, SqlStdOperatorTable.PATTERN_CONCAT,
list);
}
代码示例来源:origin: Qihoo360/Quicksql
private SqlNode createLeftCall(SqlOperator op, List<SqlNode> nodeList) {
if (nodeList.size() == 2) {
return op.createCall(new SqlNodeList(nodeList, POS));
}
final List<SqlNode> butLast = Util.skipLast(nodeList);
final SqlNode last = nodeList.get(nodeList.size() - 1);
final SqlNode call = createLeftCall(op, butLast);
return op.createCall(new SqlNodeList(ImmutableList.of(call, last), POS));
}
代码示例来源:origin: apache/flink
Collection<SqlMoniker> hintList) {
List<String> subNames = Util.skipLast(names);
new SqlValidatorScope.ResolvedImpl();
final SqlNameMatcher nameMatcher = catalogReader.nameMatcher();
scope.resolve(ImmutableList.of(name), nameMatcher, false, resolved);
if (resolved.count() == 1) {
ns = resolved.only().namespace;
for (RelDataTypeField field : rowType.getFieldList()) {
hintList.add(
new SqlMonikerImpl(
field.getName(),
SqlMonikerType.COLUMN));
RelDataType rowType =
selectScope.getChildren().get(0).getRowType();
for (RelDataTypeField field : rowType.getFieldList()) {
hintList.add(
new SqlMonikerImpl(
field.getName(),
SqlMonikerType.COLUMN));
代码示例来源:origin: apache/flink
final List<SqlNode> oldSelectItems = ImmutableList.copyOf(selectItems);
selectItems.clear();
final List<Map.Entry<String, RelDataType>> oldFields =
ImmutableList.copyOf(fields);
fields.clear();
for (ImmutableIntList source : sources) {
RelDataType type = field.getValue();
SqlNode selectItem = oldSelectItems.get(p0);
for (int p1 : Util.skip(source)) {
final Map.Entry<String, RelDataType> field1 = oldFields.get(p1);
final SqlNode selectItem1 = oldSelectItems.get(p1);
final RelDataType type1 = field1.getValue();
final boolean nullable = type.isNullable() && type1.isNullable();
final RelDataType type2 =
SqlTypeUtil.leastRestrictiveForComparison(typeFactory, type,
代码示例来源:origin: Qihoo360/Quicksql
@Override protected void matched(List<String> prefixNames,
List<String> names) {
matchedNames = ImmutableList.copyOf(
Util.startsWith(names, prefixNames)
? Util.skip(names, prefixNames.size())
: names);
}
代码示例来源:origin: org.apache.calcite/calcite-druid
final DruidQuery query = call.rel(1);
final RelOptCluster cluster = project.getCluster();
final RexBuilder rexBuilder = cluster.getRexBuilder();
if (!DruidQuery.isValidSignature(query.signature() + 'p')) {
return;
ImmutableList.of(Util.last(query.rels)));
RelNode newNode = DruidQuery.extendQuery(query, newProject);
call.transformTo(newNode);
final List<RexNode> below = pair.right;
final RelDataTypeFactory.Builder builder =
cluster.getTypeFactory().builder();
final RelNode input = Util.last(query.rels);
for (RexNode e : below) {
final String name;
if (e instanceof RexInputRef) {
name = input.getRowType().getFieldNames().get(((RexInputRef) e).getIndex());
} else {
name = null;
builder.add(name, e.getType());
代码示例来源:origin: apache/hive
/** Returns references to the fields of a given input. */
public ImmutableList<RexNode> fields(int inputCount, int inputOrdinal) {
final RelNode input = peek(inputCount, inputOrdinal);
final RelDataType rowType = input.getRowType();
final ImmutableList.Builder<RexNode> nodes = ImmutableList.builder();
for (int fieldOrdinal : Util.range(rowType.getFieldCount())) {
nodes.add(field(inputCount, inputOrdinal, fieldOrdinal));
}
return nodes.build();
}
代码示例来源:origin: apache/hive
RexBuilder rexBuilder = filterRel.getCluster().getRexBuilder();
final RelBuilder relBuilder = call.builder();
List<RelDataTypeField> origFields = setOp.getRowType().getFieldList();
int[] adjustments = new int[origFields.size()];
final List<RelNode> newSetOpInputs = new ArrayList<>();
for (int index = 0; index < setOp.getInputs().size(); index++) {
RelNode input = setOp.getInput(index);
RexNode newCondition = condition.accept(new RelOptUtil.RexInputConverter(rexBuilder,
origFields, input.getRowType().getFieldList(), adjustments));
if (setOp instanceof Union && setOp.all) {
final RelMetadataQuery mq = call.getMetadataQuery();
final RelOptPredicateList predicates = mq.getPulledUpPredicates(input);
if (predicates != null) {
ImmutableList.Builder<RexNode> listBuilder = ImmutableList.builder();
listBuilder.addAll(predicates.pulledUpPredicates);
listBuilder.add(newCondition);
RexExecutor executor =
Util.first(filterRel.getCluster().getPlanner().getExecutor(), RexUtil.EXECUTOR);
final RexSimplify simplify =
new RexSimplify(rexBuilder, true, executor);
final RexNode x = simplify.simplifyAnds(listBuilder.build());
if (x.isAlwaysFalse()) {
代码示例来源:origin: apache/flink
for (i = id.names.size() - 1; i > 0; i--) {
final SqlValidatorScope.ResolvedImpl resolved =
new SqlValidatorScope.ResolvedImpl();
scope.resolve(id.names.subList(0, i), nameMatcher, false, resolved);
if (resolved.count() == 1) {
for (SqlValidatorScope.Step p : Util.skip(resolve.path.steps())) {
type = type.getFieldList().get(p.i).getType();
if (type == null || id.names.size() == 1) {
RESOURCE.unknownField(name));
type = field.getType();
代码示例来源:origin: org.apache.calcite/calcite-core
/** Adds a lattice column based on a SQL expression,
* or returns a column based on the same expression seen previously. */
public Column expression(RexNode e, String alias,
List<String> tableAliases) {
return derivedColumnsByName.computeIfAbsent(e.toString(), k -> {
final int derivedOrdinal = derivedColumnsByName.size();
final int ordinal = baseColumns.size() + derivedOrdinal;
return new DerivedColumn(ordinal,
Util.first(alias, "e$" + derivedOrdinal), e, tableAliases);
});
}
代码示例来源:origin: Qihoo360/Quicksql
private List<Pair<ColumnMetaData.Rep, Integer>> fieldClasses(
final JavaTypeFactory typeFactory) {
final RelDataType rowType = protoRowType.apply(typeFactory);
return Lists.transform(rowType.getFieldList(), f -> {
final RelDataType type = f.getType();
final Class clazz = (Class) typeFactory.getJavaClass(type);
final ColumnMetaData.Rep rep =
Util.first(ColumnMetaData.Rep.of(clazz),
ColumnMetaData.Rep.OBJECT);
return Pair.of(rep, type.getSqlTypeName().getJdbcOrdinal());
});
}
代码示例来源:origin: Qihoo360/Quicksql
@Override public RelDataType deriveRowType() {
return getCluster().getTypeFactory().createStructType(
Pair.right(Util.last(rels).getRowType().getFieldList()),
getQuerySpec().fieldNames);
}
代码示例来源:origin: apache/drill
final String name = nameIterator.hasNext() ? nameIterator.next() : null;
final String name2 = inferAlias(exprList, node);
names.add(Util.first(name, name2));
final RelDataType inputRowType = peek().getRowType();
if (!force && RexUtil.isIdentity(exprList, inputRowType)) {
if (names.equals(inputRowType.getFieldNames())) {
RexUtil.createStructType(cluster.getTypeFactory(), exprList,
names, SqlValidatorUtil.F_SUGGESTER);
stack.push(
代码示例来源:origin: Qihoo360/Quicksql
protected RexNode handle(RexFieldAccess fieldAccess) {
final RexCorrelVariable v =
(RexCorrelVariable) fieldAccess.getReferenceExpr();
if (v.id.equals(correlation)
&& v.getType().getFieldCount() == mapping.getSourceCount()) {
final int old = fieldAccess.getField().getIndex();
final int new_ = mapping.getTarget(old);
final RelDataTypeFactory.Builder typeBuilder =
relBuilder.getTypeFactory().builder();
for (int target : Util.range(mapping.getTargetCount())) {
typeBuilder.add(
v.getType().getFieldList().get(mapping.getSource(target)));
}
final RexNode newV =
rexBuilder.makeCorrel(typeBuilder.build(), v.id);
if (old != new_) {
return rexBuilder.makeFieldAccess(newV, new_);
}
}
return fieldAccess;
}
});
代码示例来源:origin: apache/flink
final Table table = modifiableViewTable.unwrap(Table.class);
final RelDataType tableRowType = table.getRowType(typeFactory);
final List<RelDataTypeField> tableFields = tableRowType.getFieldList();
final String colName = tableFields.get(colIndex).getName();
final RelDataTypeField targetField = tableIndexToTargetField.get(colIndex);
for (SqlNode row : values) {
final SqlCall call = (SqlCall) row;
final SqlNode sourceValue = call.operand(targetField.getIndex());
final ValidationError validationError =
new ValidationError(sourceValue,
RESOURCE.viewConstraintNotSatisfied(colName,
Util.last(validatorTable.getQualifiedName())));
RelOptUtil.validateValueAgainstConstraint(sourceValue,
projectMap.get(colIndex), validationError);
代码示例来源:origin: org.apache.calcite/calcite-core
private RexLiteral dateTimeLiteral(RexBuilder rexBuilder, Calendar calendar,
RexNode operand) {
final TimestampString ts;
final int p;
switch (operand.getType().getSqlTypeName()) {
case TIMESTAMP:
ts = TimestampString.fromCalendarFields(calendar);
p = operand.getType().getPrecision();
return rexBuilder.makeTimestampLiteral(ts, p);
case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
ts = TimestampString.fromCalendarFields(calendar);
final TimeZone tz = TimeZone.getTimeZone(this.timeZone);
final TimestampString localTs =
new TimestampWithTimeZoneString(ts, tz)
.withTimeZone(DateTimeUtils.UTC_ZONE)
.getLocalTimestampString();
p = operand.getType().getPrecision();
return rexBuilder.makeTimestampWithLocalTimeZoneLiteral(localTs, p);
case DATE:
final DateString d = DateString.fromCalendarFields(calendar);
return rexBuilder.makeDateLiteral(d);
default:
throw Util.unexpected(operand.getType().getSqlTypeName());
}
}
内容来源于网络,如有侵权,请联系作者删除!