Java Code Examples for org.apache.calcite.rel.type.RelDataTypeFactory#createMultisetType()

The following examples show how to use org.apache.calcite.rel.type.RelDataTypeFactory#createMultisetType() . 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: AbstractNamespace.java    From Bats with Apache License 2.0 6 votes vote down vote up
protected RelDataType convertToStruct(RelDataType type) {
  // "MULTISET [<expr>, ...]" needs to be wrapped in a record if
  // <expr> has a scalar type.
  // For example, "MULTISET [8, 9]" has type
  // "RECORD(INTEGER EXPR$0 NOT NULL) NOT NULL MULTISET NOT NULL".
  final RelDataType componentType = type.getComponentType();
  if (componentType == null || componentType.isStruct()) {
    return type;
  }
  final RelDataTypeFactory typeFactory = validator.getTypeFactory();
  final RelDataType structType = toStruct(componentType, getNode());
  final RelDataType collectionType;
  switch (type.getSqlTypeName()) {
  case ARRAY:
    collectionType = typeFactory.createArrayType(structType, -1);
    break;
  case MULTISET:
    collectionType = typeFactory.createMultisetType(structType, -1);
    break;
  default:
    throw new AssertionError(type);
  }
  return typeFactory.createTypeWithNullability(collectionType,
      type.isNullable());
}
 
Example 2
Source File: AbstractNamespace.java    From calcite with Apache License 2.0 6 votes vote down vote up
protected RelDataType convertToStruct(RelDataType type) {
  // "MULTISET [<expr>, ...]" needs to be wrapped in a record if
  // <expr> has a scalar type.
  // For example, "MULTISET [8, 9]" has type
  // "RECORD(INTEGER EXPR$0 NOT NULL) NOT NULL MULTISET NOT NULL".
  final RelDataType componentType = type.getComponentType();
  if (componentType == null || componentType.isStruct()) {
    return type;
  }
  final RelDataTypeFactory typeFactory = validator.getTypeFactory();
  final RelDataType structType = toStruct(componentType, getNode());
  final RelDataType collectionType;
  switch (type.getSqlTypeName()) {
  case ARRAY:
    collectionType = typeFactory.createArrayType(structType, -1);
    break;
  case MULTISET:
    collectionType = typeFactory.createMultisetType(structType, -1);
    break;
  default:
    throw new AssertionError(type);
  }
  return typeFactory.createTypeWithNullability(collectionType,
      type.isNullable());
}
 
Example 3
Source File: SqlTypeUtil.java    From Bats with Apache License 2.0 5 votes vote down vote up
public static RelDataType createMultisetType(
    RelDataTypeFactory typeFactory,
    RelDataType type,
    boolean nullable) {
  RelDataType ret = typeFactory.createMultisetType(type, -1);
  return typeFactory.createTypeWithNullability(ret, nullable);
}
 
Example 4
Source File: ExtendedSqlCollectionTypeNameSpec.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Create collection data type.
 *
 * @param elementType Type of the collection element
 * @param typeFactory Type factory
 * @return The collection data type, or throw exception if the collection
 *         type name does not belong to {@code SqlTypeName} enumerations
 */
private RelDataType createCollectionType(RelDataType elementType,
		RelDataTypeFactory typeFactory) {
	switch (collectionTypeName) {
	case MULTISET:
		return typeFactory.createMultisetType(elementType, -1);
	case ARRAY:
		return typeFactory.createArrayType(elementType, -1);

	default:
		throw Util.unexpected(collectionTypeName);
	}
}
 
Example 5
Source File: SqlCollectionTypeNameSpec.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Create collection data type.
 *
 * @param elementType Type of the collection element
 * @param typeFactory Type factory
 * @return The collection data type, or throw exception if the collection
 *         type name does not belong to {@code SqlTypeName} enumerations
 */
private RelDataType createCollectionType(RelDataType elementType,
    RelDataTypeFactory typeFactory) {
  switch (collectionTypeName) {
  case MULTISET:
    return typeFactory.createMultisetType(elementType, -1);
  case ARRAY:
    return typeFactory.createArrayType(elementType, -1);

  default:
    throw Util.unexpected(collectionTypeName);
  }
}
 
Example 6
Source File: SqlTypeUtil.java    From calcite with Apache License 2.0 5 votes vote down vote up
public static RelDataType createMultisetType(
    RelDataTypeFactory typeFactory,
    RelDataType type,
    boolean nullable) {
  RelDataType ret = typeFactory.createMultisetType(type, -1);
  return typeFactory.createTypeWithNullability(ret, nullable);
}
 
Example 7
Source File: FlinkSqlDataTypeSpec.java    From flink with Apache License 2.0 4 votes vote down vote up
private RelDataType getExtendedType(RelDataTypeFactory typeFactory, SqlIdentifier typeName) {
	// quick check.
	if (!(typeName instanceof ExtendedSqlType)) {
		return null;
	}
	if (typeName instanceof SqlBytesType) {
		return typeFactory.createSqlType(SqlTypeName.VARBINARY, Integer.MAX_VALUE);
	} else if (typeName instanceof SqlStringType) {
		return typeFactory.createSqlType(SqlTypeName.VARCHAR, Integer.MAX_VALUE);
	} else if (typeName instanceof SqlArrayType) {
		final SqlArrayType arrayType = (SqlArrayType) typeName;
		return typeFactory.createArrayType(arrayType.getElementType()
			.deriveType(typeFactory), -1);
	} else if (typeName instanceof SqlMultisetType) {
		final SqlMultisetType multiSetType = (SqlMultisetType) typeName;
		return typeFactory.createMultisetType(multiSetType.getElementType()
			.deriveType(typeFactory), -1);
	} else if (typeName instanceof SqlMapType) {
		final SqlMapType mapType = (SqlMapType) typeName;
		return typeFactory.createMapType(
			mapType.getKeyType().deriveType(typeFactory),
			mapType.getValType().deriveType(typeFactory));
	} else if (typeName instanceof SqlRowType) {
		final SqlRowType rowType = (SqlRowType) typeName;
		return typeFactory.createStructType(
			rowType.getFieldTypes().stream().map(ft -> ft.deriveType(typeFactory))
				.collect(Collectors.toList()),
			rowType.getFieldNames().stream().map(SqlIdentifier::getSimple)
				.collect(Collectors.toList()));
	} else if (typeName instanceof SqlTimeType) {
		final SqlTimeType zonedTimeType = (SqlTimeType) typeName;
		if (zonedTimeType.getPrecision() >= 0) {
			return typeFactory.createSqlType(zonedTimeType.getSqlTypeName(),
				zonedTimeType.getPrecision());
		} else {
			// Use default precision.
			return typeFactory.createSqlType(zonedTimeType.getSqlTypeName());
		}
	} else if (typeName instanceof SqlTimestampType) {
		final SqlTimestampType zonedTimestampType = (SqlTimestampType) typeName;
		if (zonedTimestampType.getPrecision() >= 0) {
			return typeFactory.createSqlType(zonedTimestampType.getSqlTypeName(),
				zonedTimestampType.getPrecision());
		} else {
			// Use default precision.
			return typeFactory.createSqlType(zonedTimestampType.getSqlTypeName());
		}
	}
	return null;
}
 
Example 8
Source File: CollectionsFunctions.java    From mat-calcite-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public RelDataType getReturnType(RelDataTypeFactory relDataTypeFactory) {
    return relDataTypeFactory.createMultisetType(relDataTypeFactory.createJavaType(HeapReference.class), -1);
}
 
Example 9
Source File: Handler.java    From calcite with Apache License 2.0 4 votes vote down vote up
private RelDataType toType(Ast.BagType type) {
  final RelDataTypeFactory typeFactory = builder.getTypeFactory();
  final RelDataType t = toType(type.componentType);
  return typeFactory.createMultisetType(t, -1);
}