/** * Creates a HiveProject with no sort keys. * * @param child * input relational expression * @param exps * set of expressions for the input columns * @param fieldNames * aliases of the expressions */ public static HiveProject create(RelNode child, List<? extends RexNode> exps, List<String> fieldNames) throws CalciteSemanticException{ RelOptCluster cluster = child.getCluster(); // 1 Ensure columnNames are unique - CALCITE-411 if (fieldNames != null && !Util.isDistinct(fieldNames)) { String msg = "Select list contains multiple expressions with the same name." + fieldNames; throw new CalciteSemanticException(msg, UnsupportedFeature.Same_name_in_multiple_expressions); } RelDataType rowType = RexUtil.createStructType(cluster.getTypeFactory(), exps, fieldNames); return create(cluster, child, exps, rowType, Collections.<RelCollation> emptyList()); }
/** * Creates a HiveProject with no sort keys. * * @param child * input relational expression * @param exps * set of expressions for the input columns * @param fieldNames * aliases of the expressions */ public static HiveProject create(RelNode child, List<? extends RexNode> exps, List<String> fieldNames) throws CalciteSemanticException{ RelOptCluster cluster = child.getCluster(); // 1 Ensure columnNames are unique - CALCITE-411 if (fieldNames != null && !Util.isDistinct(fieldNames)) { String msg = "Select list contains multiple expressions with the same name." + fieldNames; throw new CalciteSemanticException(msg, UnsupportedFeature.Same_name_in_multiple_expressions); } RelDataType rowType = RexUtil.createStructType(cluster.getTypeFactory(), exps, fieldNames); return create(cluster, child, exps, rowType, Collections.<RelCollation> emptyList()); }
/** Converts a list into a list with unique elements. * * <p>The order is preserved; the second and subsequent occurrences are * removed. * * <p>If the list is already unique it is returned unchanged. */ public static <E> List<E> distinctList(List<E> list) { if (isDistinct(list)) { return list; } return ImmutableList.copyOf(new LinkedHashSet<>(list)); }
/** Converts a list into a list with unique elements. * * <p>The order is preserved; the second and subsequent occurrences are * removed. * * <p>If the list is already unique it is returned unchanged. */ public static <E> List<E> distinctList(List<E> list) { if (isDistinct(list)) { return list; } return ImmutableList.copyOf(new LinkedHashSet<>(list)); }
/** Converts an iterable into a list with unique elements. * * <p>The order is preserved; the second and subsequent occurrences are * removed. * * <p>If {@code iterable} is a unique list it is returned unchanged. */ public static <E> List<E> distinctList(Iterable<E> keys) { if (keys instanceof Set) { return ImmutableList.copyOf(keys); } if (keys instanceof List) { @SuppressWarnings("unchecked") final List<E> list = (List) keys; if (isDistinct(list)) { return list; } } return ImmutableList.copyOf(Sets.newLinkedHashSet(keys)); }
/** Converts an iterable into a list with unique elements. * * <p>The order is preserved; the second and subsequent occurrences are * removed. * * <p>If {@code iterable} is a unique list it is returned unchanged. */ public static <E> List<E> distinctList(Iterable<E> keys) { if (keys instanceof Set) { return ImmutableList.copyOf(keys); } if (keys instanceof List) { @SuppressWarnings("unchecked") final List<E> list = (List) keys; if (isDistinct(list)) { return list; } } return ImmutableList.copyOf(Sets.newLinkedHashSet(keys)); }
protected RelCollationImpl(ImmutableList<RelFieldCollation> fieldCollations) { this.fieldCollations = fieldCollations; Preconditions.checkArgument( Util.isDistinct(RelCollations.ordinals(fieldCollations)), "fields must be distinct"); }
private SyntheticRecordType(RelDataType relType, String name) { this.relType = relType; this.name = name; assert relType == null || Util.isDistinct(relType.getFieldNames()) : "field names not distinct: " + relType; }
protected RelCollationImpl(ImmutableList<RelFieldCollation> fieldCollations) { this.fieldCollations = fieldCollations; Preconditions.checkArgument( Util.isDistinct(RelCollations.ordinals(fieldCollations)), "fields must be distinct"); }
private SyntheticRecordType(RelDataType relType, String name) { this.relType = relType; this.name = name; assert relType == null || Util.isDistinct(relType.getFieldNames()) : "field names not distinct: " + relType; }
protected CalciteCatalogReader(CalciteSchema rootSchema, SqlNameMatcher nameMatcher, List<List<String>> schemaPaths, RelDataTypeFactory typeFactory, CalciteConnectionConfig config) { this.rootSchema = Objects.requireNonNull(rootSchema); this.nameMatcher = nameMatcher; this.schemaPaths = Util.immutableCopy(Util.isDistinct(schemaPaths) ? schemaPaths : new LinkedHashSet<>(schemaPaths)); this.typeFactory = typeFactory; this.config = config; }
protected CalciteCatalogReader(CalciteSchema rootSchema, SqlNameMatcher nameMatcher, List<List<String>> schemaPaths, RelDataTypeFactory typeFactory, CalciteConnectionConfig config) { this.rootSchema = Objects.requireNonNull(rootSchema); this.nameMatcher = nameMatcher; this.schemaPaths = Util.immutableCopy(Util.isDistinct(schemaPaths) ? schemaPaths : new LinkedHashSet<>(schemaPaths)); this.typeFactory = typeFactory; this.config = config; }
public static RelCollation of(List<RelFieldCollation> fieldCollations) { if (Util.isDistinct(ordinals(fieldCollations))) { return new RelCollationImpl(ImmutableList.copyOf(fieldCollations)); } // Remove field collations whose field has already been seen final ImmutableList.Builder<RelFieldCollation> builder = ImmutableList.builder(); final Set<Integer> set = new HashSet<>(); for (RelFieldCollation fieldCollation : fieldCollations) { if (set.add(fieldCollation.getFieldIndex())) { builder.add(fieldCollation); } } return new RelCollationImpl(builder.build()); }
public static RelCollation of(List<RelFieldCollation> fieldCollations) { if (Util.isDistinct(ordinals(fieldCollations))) { return new RelCollationImpl(ImmutableList.copyOf(fieldCollations)); } // Remove field collations whose field has already been seen final ImmutableList.Builder<RelFieldCollation> builder = ImmutableList.builder(); final Set<Integer> set = new HashSet<>(); for (RelFieldCollation fieldCollation : fieldCollations) { if (set.add(fieldCollation.getFieldIndex())) { builder.add(fieldCollation); } } return new RelCollationImpl(builder.build()); }
/** * Unit test for {@link Util#isDistinct(java.util.List)}. */ @Test public void testDistinct() { assertTrue(Util.isDistinct(Collections.emptyList())); assertTrue(Util.isDistinct(Arrays.asList("a"))); assertTrue(Util.isDistinct(Arrays.asList("a", "b", "c"))); assertFalse(Util.isDistinct(Arrays.asList("a", "b", "a"))); assertTrue(Util.isDistinct(Arrays.asList("a", "b", null))); assertFalse(Util.isDistinct(Arrays.asList("a", null, "b", null))); }
/** * Unit test for {@link Util#isDistinct(java.util.List)}. */ @Test public void testDistinct() { assertTrue(Util.isDistinct(Collections.emptyList())); assertTrue(Util.isDistinct(Arrays.asList("a"))); assertTrue(Util.isDistinct(Arrays.asList("a", "b", "c"))); assertFalse(Util.isDistinct(Arrays.asList("a", "b", "a"))); assertTrue(Util.isDistinct(Arrays.asList("a", "b", null))); assertFalse(Util.isDistinct(Arrays.asList("a", null, "b", null))); }
public boolean isValid(Litmus litmus, Context context) { return super.isValid(litmus, context) && litmus.check(Util.isDistinct(getRowType().getFieldNames()), "distinct field names: {}", getRowType()); }
public boolean isValid(Litmus litmus, Context context) { return super.isValid(litmus, context) && litmus.check(Util.isDistinct(getRowType().getFieldNames()), "distinct field names: {}", getRowType()); }
/** * Creates a HiveProject with no sort keys. * * @param child * input relational expression * @param exps * set of expressions for the input columns * @param fieldNames * aliases of the expressions */ public static HiveProject create(RelNode child, List<? extends RexNode> exps, List<String> fieldNames) throws CalciteSemanticException{ RelOptCluster cluster = child.getCluster(); // 1 Ensure columnNames are unique - CALCITE-411 if (fieldNames != null && !Util.isDistinct(fieldNames)) { String msg = "Select list contains multiple expressions with the same name." + fieldNames; throw new CalciteSemanticException(msg, UnsupportedFeature.Same_name_in_multiple_expressions); } RelDataType rowType = RexUtil.createStructType(cluster.getTypeFactory(), exps, fieldNames); return create(cluster, child, exps, rowType, Collections.<RelCollation> emptyList()); }
if (!Util.isDistinct(rowType.getFieldNames())) { return litmus.fail("field names not distinct: {}", rowType); if (false && !Util.isDistinct(Lists.transform(exps, RexNode::toString))) {