Util.first(context.unwrap(RelFactories.AggregateFactory.class), HiveRelFactories.HIVE_AGGREGATE_FACTORY); this.filterFactory = Util.first(context.unwrap(RelFactories.FilterFactory.class), HiveRelFactories.HIVE_FILTER_FACTORY); this.projectFactory = Util.first(context.unwrap(RelFactories.ProjectFactory.class), HiveRelFactories.HIVE_PROJECT_FACTORY); this.sortFactory = Util.first(context.unwrap(RelFactories.SortFactory.class), HiveRelFactories.HIVE_SORT_FACTORY); this.setOpFactory = Util.first(context.unwrap(RelFactories.SetOpFactory.class), HiveRelFactories.HIVE_SET_OP_FACTORY); this.joinFactory = Util.first(context.unwrap(RelFactories.JoinFactory.class), HiveRelFactories.HIVE_JOIN_FACTORY); this.semiJoinFactory = Util.first(context.unwrap(RelFactories.SemiJoinFactory.class), HiveRelFactories.HIVE_SEMI_JOIN_FACTORY); this.correlateFactory = Util.first(context.unwrap(RelFactories.CorrelateFactory.class), RelFactories.DEFAULT_CORRELATE_FACTORY); this.valuesFactory = Util.first(context.unwrap(RelFactories.ValuesFactory.class), RelFactories.DEFAULT_VALUES_FACTORY); this.scanFactory = Util.first(context.unwrap(RelFactories.TableScanFactory.class), RelFactories.DEFAULT_TABLE_SCAN_FACTORY);
private void setCurrent(RelNode root, LogicalCorrelate corRel) { currentRel = corRel; if (corRel != null) { cm = new CorelMapBuilder().build(Util.first(root, corRel)); } }
private void setCurrent(RelNode root, LogicalCorrelate corRel) { currentRel = corRel; if (corRel != null) { cm = new CorelMapBuilder().build(Util.first(root, corRel)); } }
Util.first(context.unwrap(RelFactories.AggregateFactory.class), HiveRelFactories.HIVE_AGGREGATE_FACTORY); this.filterFactory = Util.first(context.unwrap(RelFactories.FilterFactory.class), HiveRelFactories.HIVE_FILTER_FACTORY); this.projectFactory = Util.first(context.unwrap(RelFactories.ProjectFactory.class), HiveRelFactories.HIVE_PROJECT_FACTORY); this.sortFactory = Util.first(context.unwrap(RelFactories.SortFactory.class), HiveRelFactories.HIVE_SORT_FACTORY); this.setOpFactory = Util.first(context.unwrap(RelFactories.SetOpFactory.class), HiveRelFactories.HIVE_SET_OP_FACTORY); this.joinFactory = Util.first(context.unwrap(RelFactories.JoinFactory.class), HiveRelFactories.HIVE_JOIN_FACTORY); this.semiJoinFactory = Util.first(context.unwrap(RelFactories.SemiJoinFactory.class), HiveRelFactories.HIVE_SEMI_JOIN_FACTORY); this.correlateFactory = Util.first(context.unwrap(RelFactories.CorrelateFactory.class), RelFactories.DEFAULT_CORRELATE_FACTORY); this.valuesFactory = Util.first(context.unwrap(RelFactories.ValuesFactory.class), RelFactories.DEFAULT_VALUES_FACTORY); this.scanFactory = Util.first(context.unwrap(RelFactories.TableScanFactory.class), RelFactories.DEFAULT_TABLE_SCAN_FACTORY);
private static RelNode getRelNode(RelNode rel) { if (rel != null && rel instanceof HepRelVertex) { rel = ((HepRelVertex) rel).getCurrentRel(); } else if (rel != null && rel instanceof RelSubset) { rel = Util.first(((RelSubset)rel).getBest(), ((RelSubset) rel).getOriginal()); } return rel; }
private static CalciteUDFInfo getUDFInfo(String hiveUdfName, ImmutableList<RelDataType> calciteArgTypes, RelDataType calciteRetType) { CalciteUDFInfo udfInfo = new CalciteUDFInfo(); udfInfo.udfName = hiveUdfName; udfInfo.returnTypeInference = ReturnTypes.explicit(calciteRetType); udfInfo.operandTypeInference = InferTypes.explicit(calciteArgTypes); ImmutableList.Builder<SqlTypeFamily> typeFamilyBuilder = new ImmutableList.Builder<SqlTypeFamily>(); for (RelDataType at : calciteArgTypes) { typeFamilyBuilder.add(Util.first(at.getSqlTypeName().getFamily(), SqlTypeFamily.ANY)); } udfInfo.operandTypeChecker = OperandTypes.family(typeFamilyBuilder.build()); return udfInfo; }
@Override public void onMatch(RelOptRuleCall call) { final RelSubset rel = call.rel(0); call.transformTo(Util.first(rel.getBest(), rel.getOriginal())); } }
private static RelFieldCollation collation(RexNode node, RelFieldCollation.Direction direction, RelFieldCollation.NullDirection nullDirection, List<RexNode> extraNodes) { switch (node.getKind()) { case INPUT_REF: return new RelFieldCollation(((RexInputRef) node).getIndex(), direction, Util.first(nullDirection, direction.defaultNullDirection())); case DESCENDING: return collation(((RexCall) node).getOperands().get(0), RelFieldCollation.Direction.DESCENDING, nullDirection, extraNodes); case NULLS_FIRST: return collation(((RexCall) node).getOperands().get(0), direction, RelFieldCollation.NullDirection.FIRST, extraNodes); case NULLS_LAST: return collation(((RexCall) node).getOperands().get(0), direction, RelFieldCollation.NullDirection.LAST, extraNodes); default: final int fieldIndex = extraNodes.size(); extraNodes.add(node); return new RelFieldCollation(fieldIndex, direction, Util.first(nullDirection, direction.defaultNullDirection())); } }
public SqlNodeList expandStar( SqlNodeList selectList, SqlSelect select, boolean includeSystemVars) { final List<SqlNode> list = new ArrayList<>(); final List<Map.Entry<String, RelDataType>> types = new ArrayList<>(); for (int i = 0; i < selectList.size(); i++) { final SqlNode selectItem = selectList.get(i); final RelDataType originalType = getValidatedNodeTypeIfKnown(selectItem); expandSelectItem( selectItem, select, Util.first(originalType, unknownType), list, catalogReader.nameMatcher().createSet(), types, includeSystemVars); } getRawSelectScope(select).setExpandedSelectList(list); return new SqlNodeList(list, SqlParserPos.ZERO); }
final String name = nameIterator.hasNext() ? nameIterator.next() : null; final String name2 = inferAlias(exprList, node); names.add(Util.first(name, name2));
private static RelFieldCollation collation(RexNode node, RelFieldCollation.Direction direction, RelFieldCollation.NullDirection nullDirection, List<RexNode> extraNodes) { switch (node.getKind()) { case INPUT_REF: return new RelFieldCollation(((RexInputRef) node).getIndex(), direction, Util.first(nullDirection, direction.defaultNullDirection())); case DESCENDING: return collation(((RexCall) node).getOperands().get(0), RelFieldCollation.Direction.DESCENDING, nullDirection, extraNodes); case NULLS_FIRST: return collation(((RexCall) node).getOperands().get(0), direction, RelFieldCollation.NullDirection.FIRST, extraNodes); case NULLS_LAST: return collation(((RexCall) node).getOperands().get(0), direction, RelFieldCollation.NullDirection.LAST, extraNodes); default: final int fieldIndex = extraNodes.size(); extraNodes.add(node); return new RelFieldCollation(fieldIndex, direction, Util.first(nullDirection, direction.defaultNullDirection())); } }
SqlAggFunction createCustomAggFunction(String funcName, RelDataType returnType, Class<?> customAggFuncClz) { RelDataTypeFactory typeFactory = getCluster().getTypeFactory(); SqlIdentifier sqlIdentifier = new SqlIdentifier(funcName, new SqlParserPos(1, 1)); AggregateFunction aggFunction = AggregateFunctionImpl.create(customAggFuncClz); List<RelDataType> argTypes = new ArrayList<RelDataType>(); List<SqlTypeFamily> typeFamilies = new ArrayList<SqlTypeFamily>(); for (FunctionParameter o : aggFunction.getParameters()) { final RelDataType type = o.getType(typeFactory); argTypes.add(type); typeFamilies.add(Util.first(type.getSqlTypeName().getFamily(), SqlTypeFamily.ANY)); } return new SqlUserDefinedAggFunction(sqlIdentifier, ReturnTypes.explicit(returnType), InferTypes.explicit(argTypes), OperandTypes.family(typeFamilies), aggFunction, false, false, typeFactory); }
final String name = nameIterator.hasNext() ? nameIterator.next() : null; final String name2 = inferAlias(exprList, node); names.add(Util.first(name, name2));
private static CalciteUDFInfo getUDFInfo(String hiveUdfName, ImmutableList<RelDataType> calciteArgTypes, RelDataType calciteRetType) { CalciteUDFInfo udfInfo = new CalciteUDFInfo(); udfInfo.udfName = hiveUdfName; udfInfo.returnTypeInference = ReturnTypes.explicit(calciteRetType); udfInfo.operandTypeInference = InferTypes.explicit(calciteArgTypes); ImmutableList.Builder<SqlTypeFamily> typeFamilyBuilder = new ImmutableList.Builder<SqlTypeFamily>(); for (RelDataType at : calciteArgTypes) { typeFamilyBuilder.add(Util.first(at.getSqlTypeName().getFamily(), SqlTypeFamily.ANY)); } udfInfo.operandTypeChecker = OperandTypes.family(typeFamilyBuilder.build()); return udfInfo; }
listBuilder.add(newCondition); RexExecutor executor = Util.first(filterRel.getCluster().getPlanner().getExecutor(), RexUtil.EXECUTOR); final RexSimplify simplify = new RexSimplify(rexBuilder, true, executor);
/** Returns {@code SECOND} for both {@code HOUR TO SECOND} and * {@code SECOND}. */ public TimeUnit getUnit() { return Util.first(timeUnitRange.endUnit, timeUnitRange.startUnit); }
/** @deprecated Use {@link RelMdUtil#getJoinRowCount(RelMetadataQuery, Join, RexNode)}. */ @Deprecated // to be removed before 2.0 public static double estimateJoinedRows( Join joinRel, RexNode condition) { final RelMetadataQuery mq = RelMetadataQuery.instance(); return Util.first(RelMdUtil.getJoinRowCount(mq, joinRel, condition), 1D); }
public R apply(RelOptCluster cluster, RelOptSchema relOptSchema, SchemaPlus rootSchema, CalciteServerStatement statement) { final CalciteSchema schema = CalciteSchema.from( Util.first(config.getDefaultSchema(), rootSchema)); return action.apply(cluster, relOptSchema, schema.root().plus()); } });
Enumerable<MetaSchema> schemas(final String catalog) { return Linq4j.asEnumerable( getConnection().rootSchema.getSubSchemaMap().values()) .select((Function1<CalciteSchema, MetaSchema>) calciteSchema -> new CalciteMetaSchema(calciteSchema, catalog, calciteSchema.getName())) .orderBy((Function1<MetaSchema, Comparable>) metaSchema -> (Comparable) FlatLists.of(Util.first(metaSchema.tableCatalog, ""), metaSchema.tableSchem)); }
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()); }); }