Java Code Examples for org.apache.calcite.rel.core.Values#getTuples()

The following examples show how to use org.apache.calcite.rel.core.Values#getTuples() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RelMdSize.java    From Bats with Apache License 2.0 6 votes vote down vote up
public List<Double> averageColumnSizes(Values rel, RelMetadataQuery mq) {
  final List<RelDataTypeField> fields = rel.getRowType().getFieldList();
  final ImmutableList.Builder<Double> list = ImmutableList.builder();
  for (int i = 0; i < fields.size(); i++) {
    RelDataTypeField field = fields.get(i);
    double d;
    if (rel.getTuples().isEmpty()) {
      d = averageTypeValueSize(field.getType());
    } else {
      d = 0;
      for (ImmutableList<RexLiteral> literals : rel.getTuples()) {
        d += typeValueSize(field.getType(),
            literals.get(i).getValueAs(Comparable.class));
      }
      d /= rel.getTuples().size();
    }
    list.add(d);
  }
  return list.build();
}
 
Example 2
Source File: RelMdSize.java    From calcite with Apache License 2.0 6 votes vote down vote up
public List<Double> averageColumnSizes(Values rel, RelMetadataQuery mq) {
  final List<RelDataTypeField> fields = rel.getRowType().getFieldList();
  final ImmutableList.Builder<Double> list = ImmutableList.builder();
  for (int i = 0; i < fields.size(); i++) {
    RelDataTypeField field = fields.get(i);
    double d;
    if (rel.getTuples().isEmpty()) {
      d = averageTypeValueSize(field.getType());
    } else {
      d = 0;
      for (ImmutableList<RexLiteral> literals : rel.getTuples()) {
        d += typeValueSize(field.getType(),
            literals.get(i).getValueAs(Comparable.class));
      }
      d /= rel.getTuples().size();
    }
    list.add(d);
  }
  return list.build();
}
 
Example 3
Source File: RelToSqlConverter.java    From quark with Apache License 2.0 5 votes vote down vote up
public Result visitValues(Values e) {
  final List<String> fields = e.getRowType().getFieldNames();
  final List<Clause> clauses = Collections.singletonList(Clause.SELECT);
  final Context context =
      new AliasContext(Collections.<Pair<String, RelDataType>>emptyList(), false);
  final List<SqlSelect> selects = new ArrayList<>();
  for (List<RexLiteral> tuple : e.getTuples()) {
    final List<SqlNode> selectList = new ArrayList<>();
    for (Pair<RexLiteral, String> literal : Pair.zip(tuple, fields)) {
      selectList.add(
          SqlStdOperatorTable.AS.createCall(
              POS,
              context.toSql(null, literal.left),
              new SqlIdentifier(literal.right, POS)));
    }
    selects.add(
        new SqlSelect(POS, SqlNodeList.EMPTY,
            new SqlNodeList(selectList, POS), null, null, null,
            null, null, null, null, null));
  }
  SqlNode query = null;
  for (SqlSelect select : selects) {
    if (query == null) {
      query = select;
    } else {
      query = SqlStdOperatorTable.UNION_ALL.createCall(POS, query,
          select);
    }
  }
  return result(query, clauses, e);
}
 
Example 4
Source File: DremioRelToSqlConverter.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
/**
 * @see #dispatch
 */
@Override
public SqlImplementor.Result visit(Values e) {
  if (getDialect().getValuesDummyTable() == null) {
    return super.visit(e);
  }


  // TODO(DX-12875): Generate a multi-row VALUES clause to push to the source
  // instead of using UNION statements.
  final List<Clause> clauses = ImmutableList.of(Clause.SELECT);
  final Map<String, RelDataType> pairs = ImmutableMap.of();
  final Context context = aliasContext(pairs, false);

  final SqlNode fromNode = new SqlIdentifier(getDialect().getValuesDummyTable(), SqlParserPos.ZERO);
  final List<String> fields = e.getRowType().getFieldNames();
  final List<SqlSelect> selects = new ArrayList<>();
  for (List<RexLiteral> tuple : e.getTuples()) {
    final List<SqlNode> selectList = new ArrayList<>();
    for (Pair<RexLiteral, String> literal : Pair.zip(tuple, fields)) {
      selectList.add(
        SqlStdOperatorTable.AS.createCall(
          POS,
          context.toSql(null, literal.left),
          new SqlIdentifier(literal.right, POS)));
    }
    selects.add(
      new SqlSelect(POS, SqlNodeList.EMPTY,
        new SqlNodeList(selectList, POS), fromNode, null, null,
        null, null, null, null, null));
  }
  SqlNode query = null;
  for (SqlSelect select : selects) {
    if (query == null) {
      query = select;
    } else {
      query = SqlStdOperatorTable.UNION_ALL.createCall(POS, query,
        select);
    }
  }
  return result(query, clauses, e, null, null);
}
 
Example 5
Source File: JdbcRules.java    From calcite with Apache License 2.0 4 votes vote down vote up
@Override public RelNode convert(RelNode rel) {
  Values values = (Values) rel;
  return new JdbcValues(values.getCluster(), values.getRowType(),
      values.getTuples(), values.getTraitSet().replace(out));
}