本文整理汇总了Java中org.apache.calcite.util.Pair.zip方法的典型用法代码示例。如果您正苦于以下问题:Java Pair.zip方法的具体用法?Java Pair.zip怎么用?Java Pair.zip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.util.Pair
的用法示例。
在下文中一共展示了Pair.zip方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyRowType
import org.apache.calcite.util.Pair; //导入方法依赖的package包/类
private static void verifyRowType(final ImmutableList<ImmutableList<RexLiteral>> tuples, RelDataType rowType){
for (List<RexLiteral> tuple : tuples) {
assert (tuple.size() == rowType.getFieldCount());
for (Pair<RexLiteral, RelDataTypeField> pair : Pair.zip(tuple, rowType.getFieldList())) {
RexLiteral literal = (RexLiteral) pair.left;
RelDataType fieldType = ((RelDataTypeField) pair.right).getType();
if ((!(RexLiteral.isNullLiteral(literal)))
&& (!(SqlTypeUtil.canAssignFrom(fieldType, literal.getType())))) {
throw new AssertionError("to " + fieldType + " from " + literal);
}
}
}
}
示例2: verifyRowType
import org.apache.calcite.util.Pair; //导入方法依赖的package包/类
private static void verifyRowType(final ImmutableList<ImmutableList<RexLiteral>> tuples, RelDataType rowType){
for (List<RexLiteral> tuple : tuples) {
assert (tuple.size() == rowType.getFieldCount());
for (Pair<RexLiteral, RelDataTypeField> pair : Pair.zip(tuple, rowType.getFieldList())) {
RexLiteral literal = pair.left;
RelDataType fieldType = pair.right.getType();
if ((!(RexLiteral.isNullLiteral(literal)))
&& (!(SqlTypeUtil.canAssignFrom(fieldType, literal.getType())))) {
throw new AssertionError("to " + fieldType + " from " + literal);
}
}
}
}
示例3: buildJoinConditions
import org.apache.calcite.util.Pair; //导入方法依赖的package包/类
/**
* Build the list of join conditions for this join.
* A join condition is built only for equality and IS NOT DISTINCT FROM comparisons. The difference is:
* null == null is FALSE whereas null IS NOT DISTINCT FROM null is TRUE
* For a use case of the IS NOT DISTINCT FROM comparison, see
* {@link org.apache.calcite.rel.rules.RemoveDistinctAggregateRule}
* @param conditions populated list of join conditions
* @param leftFields join fields from the left input
* @param rightFields join fields from the right input
*/
protected void buildJoinConditions(List<JoinCondition> conditions,
List<String> leftFields,
List<String> rightFields,
List<Integer> leftKeys,
List<Integer> rightKeys) {
List<RexNode> conjuncts = RelOptUtil.conjunctions(this.getCondition());
short i=0;
for (Pair<Integer, Integer> pair : Pair.zip(leftKeys, rightKeys)) {
final RexNode conditionExpr = conjuncts.get(i++);
final SqlKind kind = conditionExpr.getKind();
if (kind != SqlKind.EQUALS && kind != SqlKind.IS_NOT_DISTINCT_FROM) {
throw UserException.unsupportedError()
.message("Unsupported comparator in join condition %s", conditionExpr)
.build(logger);
}
conditions.add(new JoinCondition(kind.toString(),
FieldReference.getWithQuotedRef(leftFields.get(pair.left)),
FieldReference.getWithQuotedRef(rightFields.get(pair.right))));
}
}
示例4: areRowTypesEqual
import org.apache.calcite.util.Pair; //导入方法依赖的package包/类
/**
* Verifies that two row type names match.
* Does not compare nullability.
* Differs from RelOptUtil implementation by not defining types as equal if one is of type ANY.
*
* @param rowType1 row type for comparison
* @param rowType2 row type for comparison
*
* @return boolean indicating that rel data types are equivalent
*/
public static boolean areRowTypesEqual(
RelDataType rowType1,
RelDataType rowType2) {
if (rowType1 == rowType2) {
return true;
}
if (rowType2.getFieldCount() != rowType1.getFieldCount()) {
return false;
}
final List<RelDataTypeField> f1 = rowType1.getFieldList();
final List<RelDataTypeField> f2 = rowType2.getFieldList();
for (Pair<RelDataTypeField, RelDataTypeField> pair : Pair.zip(f1, f2)) {
final RelDataType type1 = pair.left.getType();
final RelDataType type2 = pair.right.getType();
// Compare row type names.
if (!type1.equals(type2)) {
return false;
}
}
return true;
}
示例5: visit
import org.apache.calcite.util.Pair; //导入方法依赖的package包/类
@Override
public RelInfo visit(RelContext context, RelNode node, List<RelInfo> inputStreams)
{
Project project = (Project)node;
if (inputStreams.size() == 0 || inputStreams.size() > 1) {
throw new UnsupportedOperationException("Project is a SingleRel");
}
FilterTransformOperator operator = context.dag
.addOperator(OperatorUtils.getUniqueOperatorName(project.getRelTypeName()), FilterTransformOperator.class);
Map<String, String> expMap = new HashMap<>();
ExpressionCompiler compiler = new ExpressionCompiler(new RexBuilder(project.getCluster().getTypeFactory()));
for (Pair<RelDataTypeField, RexNode> pair : Pair.zip(project.getRowType().getFieldList(),
project.getProjects())) {
String fieldName = OperatorUtils.getFieldName(pair.left);
String expression = compiler.getExpression(pair.right, project.getInput().getRowType(), project.getRowType());
expMap.put(fieldName, expression);
}
operator.setExpressionMap(expMap);
return new RelInfo("Project", Lists.<Operator.InputPort>newArrayList(operator.input), operator, operator.output,
project.getRowType());
}
示例6: averageRowSize
import org.apache.calcite.util.Pair; //导入方法依赖的package包/类
/** Catch-all implementation for
* {@link BuiltInMetadata.Size#averageRowSize()},
* invoked using reflection.
*
* @see org.apache.calcite.rel.metadata.RelMetadataQuery#getAverageRowSize
*/
public Double averageRowSize(RelNode rel, RelMetadataQuery mq) {
final List<Double> averageColumnSizes = mq.getAverageColumnSizes(rel);
if (averageColumnSizes == null) {
return null;
}
Double d = 0d;
final List<RelDataTypeField> fields = rel.getRowType().getFieldList();
for (Pair<Double, RelDataTypeField> p
: Pair.zip(averageColumnSizes, fields)) {
if (p.left == null) {
d += averageFieldValueSize(p.right);
} else {
d += p.left;
}
}
return d;
}
示例7: convertArguments
import org.apache.calcite.util.Pair; //导入方法依赖的package包/类
/**
* Converts arguments from {@link org.apache.calcite.sql.SqlNode} to
* java object format.
*
* @param typeFactory type factory used to convert the arguments
* @param operandList input arguments
* @param function target function to get parameter types from
* @param opName name of the operator to use in error message
* @param failOnNonLiteral true when conversion should fail on non-literal
* @return converted list of arguments
*/
public static List<Object> convertArguments(RelDataTypeFactory typeFactory,
List<SqlNode> operandList, Function function,
SqlIdentifier opName,
boolean failOnNonLiteral) {
List<Object> arguments = new ArrayList<>(operandList.size());
// Construct a list of arguments, if they are all constants.
for (Pair<FunctionParameter, SqlNode> pair
: Pair.zip(function.getParameters(), operandList)) {
try {
final Object o = getValue(pair.right);
final Object o2 = coerce(o, pair.left.getType(typeFactory));
arguments.add(o2);
} catch (NonLiteralException e) {
if (failOnNonLiteral) {
throw new IllegalArgumentException("All arguments of call to macro "
+ opName + " should be literal. Actual argument #"
+ pair.left.getOrdinal() + " (" + pair.left.getName()
+ ") is not literal: " + pair.right);
}
arguments.add(null);
}
}
return arguments;
}
示例8: match
import org.apache.calcite.util.Pair; //导入方法依赖的package包/类
/**
* Matches a relational expression to a rule.
*
* @param operand Root operand of rule
* @param rel Relational expression
* @param bindings Bindings, populated on successful match
* @return whether relational expression matched rule
*/
private boolean match(
RelOptRuleOperand operand,
RelNode rel,
List<RelNode> bindings) {
if (!operand.matches(rel)) {
return false;
}
bindings.add(rel);
switch (operand.childPolicy) {
case ANY:
return true;
}
List<RelOptRuleOperand> childOperands = operand.getChildOperands();
List<? extends RelNode> childRels = rel.getInputs();
if (childOperands.size() != childRels.size()) {
return false;
}
for (Pair<RelOptRuleOperand, ? extends RelNode> pair
: Pair.zip(childOperands, childRels)) {
if (!match(pair.left, pair.right, bindings)) {
return false;
}
}
return true;
}
示例9: generateCastExpressions
import org.apache.calcite.util.Pair; //导入方法依赖的package包/类
/**
* Generates a cast for a row type.
*
* @param rexBuilder RexBuilder to use for constructing casts
* @param lhsRowType target row type
* @param rhsExps expressions to be cast
* @return cast expressions
*/
public static List<RexNode> generateCastExpressions(
RexBuilder rexBuilder,
RelDataType lhsRowType,
List<RexNode> rhsExps) {
List<RelDataTypeField> lhsFields = lhsRowType.getFieldList();
List<RexNode> castExps = new ArrayList<>();
for (Pair<RelDataTypeField, RexNode> pair
: Pair.zip(lhsFields, rhsExps, true)) {
RelDataTypeField lhsField = pair.left;
RelDataType lhsType = lhsField.getType();
final RexNode rhsExp = pair.right;
RelDataType rhsType = rhsExp.getType();
if (lhsType.equals(rhsType)) {
castExps.add(rhsExp);
} else {
castExps.add(rexBuilder.makeCast(lhsType, rhsExp));
}
}
return castExps;
}
示例10: checkOperandTypes
import org.apache.calcite.util.Pair; //导入方法依赖的package包/类
public boolean checkOperandTypes(
SqlCallBinding callBinding,
boolean throwOnFailure) {
// Do not use callBinding.operands(). We have not resolved to a function
// yet, therefore we do not know the ordered parameter names.
final List<SqlNode> operands = callBinding.getCall().getOperandList();
for (Pair<RelDataType, SqlNode> pair : Pair.zip(paramTypes, operands)) {
RelDataType argType =
callBinding.getValidator().deriveType(
callBinding.getScope(),
pair.right);
if (!SqlTypeUtil.canAssignFrom(pair.left, argType)) {
if (throwOnFailure) {
throw callBinding.newValidationSignatureError();
} else {
return false;
}
}
}
return true;
}
示例11: rename
import org.apache.calcite.util.Pair; //导入方法依赖的package包/类
private LogicalOperator rename(DrillImplementor implementor, LogicalOperator inputOp, List<String> inputFields, List<String> outputFields) {
Project.Builder builder = Project.builder();
builder.setInput(inputOp);
for (Pair<String, String> pair : Pair.zip(inputFields, outputFields)) {
builder.addExpr(new FieldReference(pair.right), new FieldReference(pair.left));
}
return builder.build();
}
示例12: buildJoinConditions
import org.apache.calcite.util.Pair; //导入方法依赖的package包/类
/**
* Build the list of join conditions for this join.
* A join condition is built only for equality and IS NOT DISTINCT FROM comparisons. The difference is:
* null == null is FALSE whereas null IS NOT DISTINCT FROM null is TRUE
* For a use case of the IS NOT DISTINCT FROM comparison, see
* {@link org.apache.calcite.rel.rules.RemoveDistinctAggregateRule}
* @param conditions populated list of join conditions
* @param leftFields join fields from the left input
* @param rightFields join fields from the right input
*/
protected void buildJoinConditions(List<JoinCondition> conditions,
List<String> leftFields,
List<String> rightFields,
List<Integer> leftKeys,
List<Integer> rightKeys) {
List<RexNode> conjuncts = RelOptUtil.conjunctions(this.getCondition());
short i=0;
RexNode comp1 = null, comp2 = null;
for (Pair<Integer, Integer> pair : Pair.zip(leftKeys, rightKeys)) {
if (comp1 == null) {
comp1 = conjuncts.get(i++);
if ( ! (comp1.getKind() == SqlKind.EQUALS || comp1.getKind() == SqlKind.IS_NOT_DISTINCT_FROM)) {
throw new IllegalArgumentException("This type of join only supports '=' and 'is not distinct from' comparators.");
}
} else {
comp2 = conjuncts.get(i++);
if (comp1.getKind() != comp2.getKind()) {
// it does not seem necessary at this time to support join conditions which have mixed comparators - e.g
// 'a1 = a2 AND b1 IS NOT DISTINCT FROM b2'
String msg = String.format("This type of join does not support mixed comparators: '%s' and '%s'.", comp1, comp2);
throw new IllegalArgumentException(msg);
}
}
conditions.add(new JoinCondition(comp1.getKind().toString(), FieldReference.getWithQuotedRef(leftFields.get(pair.left)),
FieldReference.getWithQuotedRef(rightFields.get(pair.right))));
}
}
示例13: getProjectExpressions
import org.apache.calcite.util.Pair; //导入方法依赖的package包/类
@Override
protected List<NamedExpression> getProjectExpressions(DrillParseContext context) {
List<NamedExpression> expressions = Lists.newArrayList();
for (Pair<RexNode, String> pair : Pair.zip(exps, getRowType().getFieldNames())) {
LogicalExpression expr = DrillOptiq.toDrill(context, getInput(), pair.left);
expressions.add(new NamedExpression(expr, FieldReference.getWithQuotedRef(pair.right)));
}
return expressions;
}
示例14: rename
import org.apache.calcite.util.Pair; //导入方法依赖的package包/类
private LogicalOperator rename(LogicalPlanImplementor implementor, LogicalOperator inputOp, List<String> inputFields, List<String> outputFields) {
Project.Builder builder = Project.builder();
builder.setInput(inputOp);
for (Pair<String, String> pair : Pair.zip(inputFields, outputFields)) {
builder.addExpr(new FieldReference(pair.right), new FieldReference(pair.left));
}
return builder.build();
}
示例15: getProjectExpressions
import org.apache.calcite.util.Pair; //导入方法依赖的package包/类
@Override
protected List<NamedExpression> getProjectExpressions(ParseContext context) {
List<NamedExpression> expressions = Lists.newArrayList();
for (Pair<RexNode, String> pair : Pair.zip(exps, getRowType().getFieldNames())) {
LogicalExpression expr = RexToExpr.toExpr(context, getInput(), pair.left);
expressions.add(new NamedExpression(expr, FieldReference.getWithQuotedRef(pair.right)));
}
return expressions;
}