本文整理汇总了Java中org.apache.calcite.util.Pair类的典型用法代码示例。如果您正苦于以下问题:Java Pair类的具体用法?Java Pair怎么用?Java Pair使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Pair类属于org.apache.calcite.util包,在下文中一共展示了Pair类的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: getPlan
import org.apache.calcite.util.Pair; //导入依赖的package包/类
@Override
public PhysicalPlan getPlan(SqlHandlerConfig config, String sql, SqlNode sqlNode) throws Exception {
try{
final ConvertedRelNode convertedRelNode = PrelTransformer.validateAndConvert(config, sqlNode);
final RelDataType validatedRowType = convertedRelNode.getValidatedRowType();
final RelNode queryRelNode = convertedRelNode.getConvertedNode();
final Rel drel = PrelTransformer.convertToDrel(config, queryRelNode, validatedRowType);
final Pair<Prel, String> convertToPrel = PrelTransformer.convertToPrel(config, drel);
final Prel prel = convertToPrel.getKey();
textPlan = convertToPrel.getValue();
final PhysicalOperator pop = PrelTransformer.convertToPop(config, prel);
final PhysicalPlan plan = PrelTransformer.convertToPlan(config, pop);
logger.debug("Final Physical Plan {}", textPlan);
PrelTransformer.log(config, "Dremio Plan", plan, logger);
return plan;
}catch(Exception ex){
throw SqlExceptionHelper.coerceException(logger, sql, ex, true);
}
}
示例5: 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;
}
示例6: isSimpleColumnSelection
import org.apache.calcite.util.Pair; //导入依赖的package包/类
public static boolean isSimpleColumnSelection(Project project) {
HashSet<Integer> inputRefReferenced = new HashSet<>();
for (Pair<RexNode, String> proj : project.getNamedProjects()) {
if (proj.getKey().getKind() != SqlKind.INPUT_REF) {
return false;
}
RexInputRef inputRef = (RexInputRef) proj.getKey();
// If the input reference is again referenced, then it is not a simple column selection (since it is not a permutation).
if (inputRefReferenced.contains(inputRef.getIndex())) {
return false;
}
final String nameOfProjectField = proj.getValue();
final String nameOfInput = project.getInput().getRowType().getFieldNames().get(inputRef.getIndex());
// Renaming a column is not a simple column selection
if (nameOfProjectField == null || !nameOfProjectField.equals(nameOfInput)) {
return false;
}
inputRefReferenced.add(inputRef.getIndex());
}
return true;
}
示例7: createDS
import org.apache.calcite.util.Pair; //导入依赖的package包/类
private Pair<String, Long> createDS(DatasetVersionMutator service, String path, String name, String table, DatasetVersion version,
Pair<String, Long> idVersionPair)
throws NamespaceException, DatasetNotFoundException {
DatasetPath path1 = new DatasetPath(path);
VirtualDatasetUI ds1 = new VirtualDatasetUI();
ds1.setFullPathList(path1.toPathList());
ds1.setVersion(version);
ds1.setSavedVersion(idVersionPair == null ? null : idVersionPair.getValue());
ds1.setName(name);
ds1.setState(new VirtualDatasetState(new FromTable(path1.toPathString()).wrap()));
ds1.getState().setColumnsList(asList(new Column("foo", new ExpColumnReference("bar").wrap())));
ds1.setSql("select * from " + table);
ds1.setId(idVersionPair == null ? null : idVersionPair.getKey());
ViewFieldType type = new ViewFieldType("hello", "float");
ds1.setSqlFieldsList(Collections.singletonList(type));
ds1.setCalciteFieldsList(Collections.singletonList(type));
service.put(ds1);
service.putVersion(ds1);
VirtualDatasetUI dsOut = service.get(path1);
return Pair.of(dsOut.getId(), dsOut.getSavedVersion());
}
示例8: extractJoinColumns
import org.apache.calcite.util.Pair; //导入依赖的package包/类
private List<Pair<Integer, Integer>> extractJoinColumns(int leftRowColumnCount) {
// it's a CROSS JOIN because: condition == true
if (condition instanceof RexLiteral && (Boolean) ((RexLiteral) condition).getValue()) {
throw new UnsupportedOperationException("CROSS JOIN is not supported!");
}
RexCall call = (RexCall) condition;
List<Pair<Integer, Integer>> pairs = new ArrayList<>();
if ("AND".equals(call.getOperator().getName())) {
List<RexNode> operands = call.getOperands();
for (RexNode rexNode : operands) {
Pair<Integer, Integer> pair = extractOneJoinColumn((RexCall) rexNode, leftRowColumnCount);
pairs.add(pair);
}
} else if ("=".equals(call.getOperator().getName())) {
pairs.add(extractOneJoinColumn(call, leftRowColumnCount));
} else {
throw new UnsupportedOperationException(
"Operator " + call.getOperator().getName() + " is not supported in join condition");
}
return pairs;
}
示例9: flatten
import org.apache.calcite.util.Pair; //导入依赖的package包/类
public void flatten(
List<RelNode> rels,
int systemFieldCount,
int[] start,
List<Pair<RelNode, Integer>> relOffsetList) {
for (RelNode rel : rels) {
if (leaves.contains(rel)) {
relOffsetList.add(
Pair.of(rel, start[0]));
start[0] += rel.getRowType().getFieldCount();
} else {
if (rel instanceof LogicalJoin
|| rel instanceof LogicalAggregate) {
start[0] += systemFieldCount;
}
flatten(
rel.getInputs(),
systemFieldCount,
start,
relOffsetList);
}
}
}
示例10: addGroupExpr
import org.apache.calcite.util.Pair; //导入依赖的package包/类
public int addGroupExpr(SqlNode expr) {
int ref = lookupGroupExpr(expr);
if (ref >= 0) {
return ref;
}
final int index = groupExprs.size();
groupExprs.add(expr);
String name = nameMap.get(expr.toString());
RexNode convExpr = bb.convertExpression(expr);
addExpr(convExpr, name);
if (expr instanceof SqlCall) {
SqlCall call = (SqlCall) expr;
for (Pair<SqlNode, AuxiliaryConverter> p
: SqlStdOperatorTable.convertGroupToAuxiliaryCalls(call)) {
addAuxiliaryGroupExpr(p.left, index, p.right);
}
}
return index;
}
示例11: convertGroupToAuxiliaryCalls
import org.apache.calcite.util.Pair; //导入依赖的package包/类
/** Converts a call to a grouped window function to a call to its auxiliary
* window function(s). For other calls returns null.
*
* <p>For example, converts {@code TUMBLE_START(rowtime, INTERVAL '1' HOUR))}
* to {@code TUMBLE(rowtime, INTERVAL '1' HOUR))}. */
public static List<Pair<SqlNode, AuxiliaryConverter>>
convertGroupToAuxiliaryCalls(SqlCall call) {
final SqlOperator op = call.getOperator();
if (op instanceof SqlGroupFunction
&& op.isGroup()) {
ImmutableList.Builder<Pair<SqlNode, AuxiliaryConverter>> builder =
ImmutableList.builder();
for (final SqlGroupFunction f
: ((SqlGroupFunction) op).getAuxiliaryFunctions()) {
builder.add(
Pair.<SqlNode, AuxiliaryConverter>of(copy(call, f),
new AuxiliaryConverter.Impl(f)));
}
return builder.build();
}
return ImmutableList.of();
}
示例12: 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());
}
示例13: register
import org.apache.calcite.util.Pair; //导入依赖的package包/类
private SyntheticRecordType register(
final SyntheticRecordType syntheticType) {
final List<Pair<Type, Boolean>> key =
new AbstractList<Pair<Type, Boolean>>() {
public Pair<Type, Boolean> get(int index) {
final Types.RecordField field =
syntheticType.getRecordFields().get(index);
return Pair.of(field.getType(), field.nullable());
}
public int size() {
return syntheticType.getRecordFields().size();
}
};
SyntheticRecordType syntheticType2 = syntheticTypes.get(key);
if (syntheticType2 == null) {
syntheticTypes.put(key, syntheticType);
return syntheticType;
} else {
return syntheticType2;
}
}
示例14: flatten
import org.apache.calcite.util.Pair; //导入依赖的package包/类
public void flatten(
List<RelNode> rels,
int systemFieldCount,
int[] start,
List<Pair<RelNode, Integer>> relOffsetList) {
for (RelNode rel : rels) {
if (leaves.contains(rel) || rel instanceof LogicalMatch) {
relOffsetList.add(
Pair.of(rel, start[0]));
start[0] += rel.getRowType().getFieldCount();
} else {
if (rel instanceof LogicalJoin
|| rel instanceof LogicalAggregate) {
start[0] += systemFieldCount;
}
flatten(
rel.getInputs(),
systemFieldCount,
start,
relOffsetList);
}
}
}
示例15: addGroupExpr
import org.apache.calcite.util.Pair; //导入依赖的package包/类
public int addGroupExpr(SqlNode expr) {
int ref = lookupGroupExpr(expr);
if (ref >= 0) {
return ref;
}
final int index = groupExprs.size();
groupExprs.add(expr);
String name = nameMap.get(expr.toString());
RexNode convExpr = bb.convertExpression(expr);
addExpr(convExpr, name);
if (expr instanceof SqlCall) {
SqlCall call = (SqlCall) expr;
for (Pair<SqlNode, AuxiliaryConverter> p
: SqlStdOperatorTable.convertGroupToAuxiliaryCalls(call)) {
addAuxiliaryGroupExpr(p.left, index, p.right);
}
}
return index;
}