org.apache.calcite.sql.type.MapSqlType Java Examples

The following examples show how to use org.apache.calcite.sql.type.MapSqlType. 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: RelSchemaConverter.java    From samza with Apache License 2.0 5 votes vote down vote up
public RelDataType getRelDataType(SqlFieldSchema fieldSchema) {
  switch (fieldSchema.getFieldType()) {
    case ARRAY:
      RelDataType elementType = getRelDataType(fieldSchema.getElementSchema());
      return new ArraySqlType(elementType, true);
    case BOOLEAN:
      return createTypeWithNullability(createSqlType(SqlTypeName.BOOLEAN), true);
    case DOUBLE:
      return createTypeWithNullability(createSqlType(SqlTypeName.DOUBLE), true);
    case REAL:
      return createTypeWithNullability(createSqlType(SqlTypeName.REAL), true);
    case FLOAT:
      return createTypeWithNullability(createSqlType(SqlTypeName.FLOAT), true);
    case STRING:
      return createTypeWithNullability(createSqlType(SqlTypeName.VARCHAR), true);
    case BYTES:
      return createTypeWithNullability(createSqlType(SqlTypeName.VARBINARY), true);
    case INT16:
    case INT32:
      return createTypeWithNullability(createSqlType(SqlTypeName.INTEGER), true);
    case INT64:
      return createTypeWithNullability(createSqlType(SqlTypeName.BIGINT), true);
    case ROW:
    case ANY:
      // TODO Calcite execution engine doesn't support record type yet.
      return createTypeWithNullability(createSqlType(SqlTypeName.ANY), true);
    case MAP:
      RelDataType valueType = getRelDataType(fieldSchema.getValueSchema());
      return new MapSqlType(createSqlType(SqlTypeName.VARCHAR), valueType, true);
    default:
      String msg = String.format("Field Type %s is not supported", fieldSchema.getFieldType());
      LOG.error(msg);
      throw new SamzaException(msg);
  }
}
 
Example #2
Source File: EnumerableUncollect.java    From calcite with Apache License 2.0 4 votes vote down vote up
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
  final BlockBuilder builder = new BlockBuilder();
  final EnumerableRel child = (EnumerableRel) getInput();
  final Result result = implementor.visitChild(this, 0, child, pref);
  final PhysType physType =
      PhysTypeImpl.of(
          implementor.getTypeFactory(),
          getRowType(),
          JavaRowFormat.LIST);

  // final Enumerable<List<Employee>> child = <<child adapter>>;
  // return child.selectMany(FLAT_PRODUCT);
  final Expression child_ =
      builder.append(
          "child", result.block);

  final List<Integer> fieldCounts = new ArrayList<>();
  final List<FlatProductInputType> inputTypes = new ArrayList<>();

  Expression lambdaForStructWithSingleItem = null;
  for (RelDataTypeField field : child.getRowType().getFieldList()) {
    final RelDataType type = field.getType();
    if (type instanceof MapSqlType) {
      fieldCounts.add(2);
      inputTypes.add(FlatProductInputType.MAP);
    } else {
      final RelDataType elementType = type.getComponentType();
      if (elementType.isStruct()) {
        if (elementType.getFieldCount() == 1 && child.getRowType().getFieldList().size() == 1
            && !withOrdinality) {
          // Solves CALCITE-4063: if we are processing a single field, which is a struct with a
          // single item inside, and no ordinality; the result must be a scalar, hence use a
          // special lambda that does not return lists, but the (single) items within those lists
          lambdaForStructWithSingleItem = Expressions.call(BuiltInMethod.FLAT_LIST.method);
        } else {
          fieldCounts.add(elementType.getFieldCount());
          inputTypes.add(FlatProductInputType.LIST);
        }
      } else {
        fieldCounts.add(-1);
        inputTypes.add(FlatProductInputType.SCALAR);
      }
    }
  }

  final Expression lambda = lambdaForStructWithSingleItem != null
      ? lambdaForStructWithSingleItem
      : Expressions.call(BuiltInMethod.FLAT_PRODUCT.method,
          Expressions.constant(Ints.toArray(fieldCounts)),
          Expressions.constant(withOrdinality),
          Expressions.constant(
              inputTypes.toArray(new FlatProductInputType[0])));
  builder.add(
      Expressions.return_(null,
          Expressions.call(child_,
              BuiltInMethod.SELECT_MANY.method,
              lambda)));
  return implementor.result(physType, builder.toBlock());
}