Ejemplo n.º 1
0
 public RelOptTableImpl getTable(final String[] names) {
   List<Pair<String, Object>> pairs = new ArrayList<Pair<String, Object>>();
   Schema schema2 = schema;
   for (int i = 0; i < names.length; i++) {
     final String name = names[i];
     Schema subSchema = schema2.getSubSchema(name);
     if (subSchema != null) {
       pairs.add(Pair.<String, Object>of(name, subSchema));
       schema2 = subSchema;
       continue;
     }
     final Table table = schema2.getTable(name);
     if (table != null) {
       pairs.add(Pair.<String, Object>of(name, table));
       if (i != names.length - 1) {
         // not enough objects to match all names
         return null;
       }
       return new RelOptTableImpl(
           this, typeFactory.createType(table.getElementType()), names, table);
     }
     return null;
   }
   return null;
 }
Ejemplo n.º 2
0
 /**
  * Returns whether this trait set subsumes another trait set.
  *
  * <p>For that to happen, each trait subsumes the corresponding trait in the other set. In
  * particular, each trait set subsumes itself, because each trait subsumes itself.
  *
  * <p>Intuitively, if a relational expression is needed that has trait set S, and trait set S1
  * subsumes S, then a relational expression R in S1 meets that need. For example, if we need a
  * relational expression that has trait set S = {enumerable convention, sorted on [C1 asc]}, and R
  * has {enumerable convention, sorted on [C1 asc, C2]}
  *
  * @param that another RelTraitSet
  * @return whether this trait set subsumes other trait set
  */
 public boolean subsumes(RelTraitSet that) {
   for (Pair<RelTrait, RelTrait> pair : Pair.zip(traits, that.traits)) {
     if (!pair.left.subsumes(pair.right)) {
       return false;
     }
   }
   return true;
 }
Ejemplo n.º 3
0
 private RelOptTableImpl getTableFrom(List<String> names, List<String> schemaNames) {
   OptiqSchema schema = getSchema(Iterables.concat(schemaNames, Util.skipLast(names)));
   if (schema == null) {
     return null;
   }
   final String name = Util.last(names);
   Pair<String, Table> pair = schema.getTable(name, caseSensitive);
   if (pair == null) {
     pair = schema.getTableBasedOnNullaryFunction(name, caseSensitive);
   }
   if (pair != null) {
     final Table table = pair.getValue();
     final String name2 = pair.getKey();
     return RelOptTableImpl.create(this, table.getRowType(typeFactory), schema.add(name2, table));
   }
   return null;
 }
Ejemplo n.º 4
0
 /** Creates a result based on a single relational expression. */
 public Result result(SqlNode node, Collection<Clause> clauses, RelNode rel) {
   final String alias2 = SqlValidatorUtil.getAlias(node, -1);
   final String alias3 = alias2 != null ? alias2 : "t";
   final String alias4 =
       SqlValidatorUtil.uniquify(alias3, aliasSet, SqlValidatorUtil.EXPR_SUGGESTER);
   final String alias5 = alias2 == null || !alias2.equals(alias4) ? alias4 : null;
   return new Result(
       node, clauses, alias5, Collections.singletonList(Pair.of(alias4, rel.getRowType())));
 }
Ejemplo n.º 5
0
 private List<Object> getList(List<Pair<String, Object>> values, String tag) {
   for (Pair<String, Object> value : values) {
     if (value.left.equals(tag)) {
       //noinspection unchecked
       return (List<Object>) value.right;
     }
   }
   final List<Object> list = new ArrayList<Object>();
   values.add(Pair.of(tag, (Object) list));
   return list;
 }
Ejemplo n.º 6
0
  /** @return true if all tuples match rowType; otherwise, assert on mismatch */
  private boolean assertRowType() {
    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();

        // TODO jvs 19-Feb-2006: strengthen this a bit.  For example,
        // overflow, rounding, and padding/truncation must already have
        // been dealt with.
        if (!RexLiteral.isNullLiteral(literal)) {
          assert (SqlTypeUtil.canAssignFrom(fieldType, literal.getType()));
        }
      }
    }
    return true;
  }
Ejemplo n.º 7
0
 public Object freeze(ColumnLoader.ValueSet valueSet) {
   final int n = valueSet.map.keySet().size();
   int extra = valueSet.containsNull ? 1 : 0;
   Comparable[] codeValues = valueSet.map.keySet().toArray(new Comparable[n + extra]);
   Arrays.sort(codeValues, 0, n);
   ColumnLoader.ValueSet codeValueSet = new ColumnLoader.ValueSet(int.class);
   for (Comparable value : valueSet.values) {
     int code;
     if (value == null) {
       code = n;
     } else {
       code = Arrays.binarySearch(codeValues, value);
       assert code >= 0 : code + ", " + value;
     }
     codeValueSet.add(code);
   }
   Object codes = representation.freeze(codeValueSet);
   return Pair.of(codes, codeValues);
 }
Ejemplo n.º 8
0
 public List<String> getFieldNames() {
   return Pair.left(fieldList);
 }
Ejemplo n.º 9
0
 /**
  * Creates a relational expression which projects an array of expressions.
  *
  * @param child input relational expression
  * @param projectList list of (expression, name) pairs
  * @param optimize Whether to optimize
  */
 public static RelNode createProject(
     RelNode child, List<Pair<RexNode, String>> projectList, boolean optimize) {
   return createProject(child, Pair.left(projectList), Pair.right(projectList), optimize);
 }
Ejemplo n.º 10
0
 public RelWriter item(String term, Object value) {
   values.add(Pair.of(term, value));
   return this;
 }
Ejemplo n.º 11
0
 public Object freeze(ColumnLoader.ValueSet valueSet) {
   final int size = valueSet.values.size();
   return Pair.of(size == 0 ? null : valueSet.values.get(0), size);
 }
Ejemplo n.º 12
0
 public void addColumn(String name, RelDataType type) {
   columnList.add(Pair.of(name, type));
 }
Ejemplo n.º 13
0
 public void addColumn(int index, String name, RelDataType type) {
   columnList.add(index, Pair.of(name, type));
 }