Java Code Examples for org.apache.calcite.rel.type.RelDataTypeFactory

The following examples show how to use org.apache.calcite.rel.type.RelDataTypeFactory. These examples are extracted from open source projects. 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 Project: Flink-CEPplus   Source File: SqlValidatorImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a validator.
 *
 * @param opTab         Operator table
 * @param catalogReader Catalog reader
 * @param typeFactory   Type factory
 * @param conformance   Compatibility mode
 */
protected SqlValidatorImpl(
	SqlOperatorTable opTab,
	SqlValidatorCatalogReader catalogReader,
	RelDataTypeFactory typeFactory,
	SqlConformance conformance) {
	this.opTab = Objects.requireNonNull(opTab);
	this.catalogReader = Objects.requireNonNull(catalogReader);
	this.typeFactory = Objects.requireNonNull(typeFactory);
	this.conformance = Objects.requireNonNull(conformance);

	unknownType = typeFactory.createUnknownType();
	booleanType = typeFactory.createSqlType(SqlTypeName.BOOLEAN);

	rewriteCalls = true;
	expandColumnReferences = true;
	aggFinder = new AggFinder(opTab, false, true, false, null);
	aggOrOverFinder = new AggFinder(opTab, true, true, false, null);
	overFinder = new AggFinder(opTab, true, false, false, aggOrOverFinder);
	groupFinder = new AggFinder(opTab, false, false, true, null);
	aggOrOverOrGroupFinder = new AggFinder(opTab, true, true, true, null);
}
 
Example 2
Source Project: Bats   Source File: ReflectiveFunctionBase.java    License: Apache License 2.0 6 votes vote down vote up
public ParameterListBuilder add(final Class<?> type, final String name,
    final boolean optional) {
  final int ordinal = builder.size();
  builder.add(
      new FunctionParameter() {
        public int getOrdinal() {
          return ordinal;
        }

        public String getName() {
          return name;
        }

        public RelDataType getType(RelDataTypeFactory typeFactory) {
          return typeFactory.createJavaType(type);
        }

        public boolean isOptional() {
          return optional;
        }
      });
  return this;
}
 
Example 3
Source Project: attic-apex-malhar   Source File: StreamEndpoint.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public RelDataType getRowType(RelDataTypeFactory typeFactory)
{
  RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
  if (fieldMapping != null) {
    for (Map.Entry<String, Class> entry : fieldMapping.entrySet()) {
      builder.add(entry.getKey(), convertField(typeFactory, entry.getValue()));
    }
  } else if (pojoClass != null) {
    for (Field field : pojoClass.getDeclaredFields()) {
      builder.add(field.getName(), convertField(typeFactory, field.getType()));
    }
  } else {
    throw new RuntimeException("Either fieldMapping or pojoClass needs to be set.");
  }

  return builder.build();
}
 
Example 4
Source Project: calcite   Source File: SqlDotOperator.java    License: Apache License 2.0 6 votes vote down vote up
@Override public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
  final RelDataType recordType = opBinding.getOperandType(0);
  switch (recordType.getSqlTypeName()) {
  case ROW:
    final String fieldName =
        opBinding.getOperandLiteralValue(1, String.class);
    final RelDataType type = opBinding.getOperandType(0)
        .getField(fieldName, false, false)
        .getType();
    if (recordType.isNullable()) {
      return typeFactory.createTypeWithNullability(type, true);
    } else {
      return type;
    }
  default:
    throw new AssertionError();
  }
}
 
Example 5
Source Project: Bats   Source File: AggregateCall.java    License: Apache License 2.0 6 votes vote down vote up
/** Creates an AggregateCall, inferring its type if {@code type} is null. */
public static AggregateCall create(SqlAggFunction aggFunction,
    boolean distinct, boolean approximate, List<Integer> argList,
    int filterArg, RelCollation collation, int groupCount,
    RelNode input, RelDataType type, String name) {
  if (type == null) {
    final RelDataTypeFactory typeFactory =
        input.getCluster().getTypeFactory();
    final List<RelDataType> types =
        SqlTypeUtil.projectTypes(input.getRowType(), argList);
    final Aggregate.AggCallBinding callBinding =
        new Aggregate.AggCallBinding(typeFactory, aggFunction, types,
            groupCount, filterArg >= 0);
    type = aggFunction.inferReturnType(callBinding);
  }
  return create(aggFunction, distinct, approximate, argList, filterArg,
      collation, type, name);
}
 
Example 6
Source Project: Bats   Source File: View.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * If view fields are present then attempts to gather them
 * into struct type, otherwise returns extension of  {@link DynamicRecordType}.
 *
 * @param factory factory for rel data types creation
 * @return struct type that describes names and types of all
 *         view fields or extension of {@link DynamicRecordType}
 *         when view fields are empty
 */
public RelDataType getRowType(RelDataTypeFactory factory) {

  // if there are no fields defined, this is a dynamic view.
  if (isDynamic()) {
    return new RelDataTypeDrillImpl(new RelDataTypeHolder(), factory);
  }

  List<RelDataType> types = new ArrayList<>(fields.size());
  List<String> names = new ArrayList<>(fields.size());
  for (Field field : fields) {
    names.add(field.getName());
    types.add(getType(field, factory));
  }
  return factory.createStructType(types, names);
}
 
Example 7
Source Project: calcite   Source File: RexBuilder.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a RexBuilder.
 *
 * @param typeFactory Type factory
 */
public RexBuilder(RelDataTypeFactory typeFactory) {
  this.typeFactory = typeFactory;
  this.booleanTrue =
      makeLiteral(
          Boolean.TRUE,
          typeFactory.createSqlType(SqlTypeName.BOOLEAN),
          SqlTypeName.BOOLEAN);
  this.booleanFalse =
      makeLiteral(
          Boolean.FALSE,
          typeFactory.createSqlType(SqlTypeName.BOOLEAN),
          SqlTypeName.BOOLEAN);
  this.charEmpty =
      makeLiteral(
          new NlsString("", null, null),
          typeFactory.createSqlType(SqlTypeName.CHAR, 0),
          SqlTypeName.CHAR);
  this.constantNull =
      makeLiteral(
          null,
          typeFactory.createSqlType(SqlTypeName.NULL),
          SqlTypeName.NULL);
}
 
Example 8
Source Project: dremio-oss   Source File: ValuesRel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Adjust the row type to remove ANY types - derive type from the literals
 *
 * @param typeFactory       RelDataTypeFactory used to create the RelDataType
 * @param rowType           Row type
 * @param tuples            RexLiterals for the Values Rel
 *
 * @return the derived RelDataType from literal.
 */
private static RelDataType adjustRowType(final RelDataTypeFactory typeFactory, final RelDataType rowType,
                                         final ImmutableList<ImmutableList<RexLiteral>> tuples) {
  final int inFieldCount = rowType.getFieldCount();
  List<RelDataType> fieldTypes = Lists.newArrayListWithExpectedSize(inFieldCount);
  List<String> fieldNames = Lists.newArrayListWithExpectedSize(inFieldCount);

  boolean changed = false;
  int i = 0;
  for (final RelDataTypeField field : rowType.getFieldList()) {
    final SqlTypeName sqlTypeName = field.getValue().getSqlTypeName();
    if (sqlTypeName == SqlTypeName.ANY) {
      fieldTypes.add(getFieldTypeFromInput(typeFactory, i, tuples));
      changed = true;
    } else {
      fieldTypes.add(field.getType());
    }
    fieldNames.add(field.getName());
  }

  if (!changed) {
    return rowType;
  }

  return typeFactory.createStructType(fieldTypes, fieldNames);
}
 
Example 9
Source Project: samza   Source File: SamzaSqlJavaTypeFactoryImpl.java    License: Apache License 2.0 6 votes vote down vote up
private static RelDataType convertToSql(final RelDataTypeFactory typeFactory,
    RelDataType type) {
  if (type instanceof RelRecordType) {
    return typeFactory.createStructType(
        Lists.transform(type.getFieldList(), a0 -> convertToSql(typeFactory, a0.getType())),
        type.getFieldNames());
  }
  if (type instanceof JavaType) {
    SqlTypeName typeName = JavaToSqlTypeConversionRules.instance().lookup(((JavaType) type).getJavaClass());
    // For unknown sql type names, return ANY sql type to make Calcite validation not fail.
    if (typeName == null) {
      typeName = SqlTypeName.ANY;
    }
    return typeFactory.createTypeWithNullability(
        typeFactory.createSqlType(typeName),
        type.isNullable());
  } else {
    return JavaTypeFactoryImpl.toSql(typeFactory, type);
  }
}
 
Example 10
@Override
public RelDataType deriveSumType(RelDataTypeFactory typeFactory, RelDataType argumentType) {
    if (argumentType instanceof BasicSqlType) {
        switch (argumentType.getSqlTypeName()) {
        case INTEGER:
        case SMALLINT:
        case TINYINT:
            return typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
                    argumentType.isNullable());
        case DECIMAL:
            return typeFactory.createTypeWithNullability(
                    typeFactory.createSqlType(SqlTypeName.DECIMAL, 19, argumentType.getScale()),
                    argumentType.isNullable());
        default:
            break;
        }
    }
    return argumentType;
}
 
Example 11
Source Project: Bats   Source File: LealoneTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RelDataType getRowType(RelDataTypeFactory typeFactory) {
    List<String> names = Lists.newArrayList();
    List<RelDataType> types = Lists.newArrayList();
    for (Column column : table.getColumns()) {
        names.add(column.getName());
        RelDataType type = getSqlTypeFromLealoneType(typeFactory, column.getType());
        type = typeFactory.createTypeWithNullability(type, column.isNullable());
        types.add(type);
    }

    return typeFactory.createStructType(types, names);
}
 
Example 12
Source Project: Bats   Source File: RexUtil.java    License: Apache License 2.0 5 votes vote down vote up
/** Returns whether an expression is a cast just for the purposes of
 * nullability, not changing any other aspect of the type. */
public static boolean isNullabilityCast(RelDataTypeFactory typeFactory, RexNode node) {
    switch (node.getKind()) {
    case CAST:
        final RexCall call = (RexCall) node;
        final RexNode arg0 = call.getOperands().get(0);
        return SqlTypeUtil.equalSansNullability(typeFactory, arg0.getType(), call.getType());
    }
    return false;
}
 
Example 13
Source Project: calcite   Source File: JavaTypeFactoryImpl.java    License: Apache License 2.0 5 votes vote down vote up
/** Converts a type in Java format to a SQL-oriented type. */
public static RelDataType toSql(final RelDataTypeFactory typeFactory,
    RelDataType type) {
  if (type instanceof RelRecordType) {
    return typeFactory.createTypeWithNullability(
        typeFactory.createStructType(
            type.getFieldList()
                .stream()
                .map(field -> toSql(typeFactory, field.getType()))
                .collect(Collectors.toList()),
            type.getFieldNames()),
        type.isNullable());
  } else if (type instanceof JavaType) {
    SqlTypeName sqlTypeName = type.getSqlTypeName();
    final RelDataType relDataType;
    if (SqlTypeUtil.isArray(type)) {
      // Transform to sql type, take care for two cases:
      // 1. type.getJavaClass() is collection with erased generic type
      // 2. ElementType returned by JavaType is also of JavaType,
      // and needs conversion using typeFactory
      final RelDataType elementType = toSqlTypeWithNullToAny(
          typeFactory, type.getComponentType());
      relDataType = typeFactory.createArrayType(elementType, -1);
    } else if (SqlTypeUtil.isMap(type)) {
      final RelDataType keyType = toSqlTypeWithNullToAny(
          typeFactory, type.getKeyType());
      final RelDataType valueType = toSqlTypeWithNullToAny(
          typeFactory, type.getValueType());
      relDataType = typeFactory.createMapType(keyType, valueType);
    } else {
      relDataType = typeFactory.createSqlType(sqlTypeName);
    }
    return typeFactory.createTypeWithNullability(relDataType, type.isNullable());
  }
  return type;
}
 
Example 14
Source Project: calcite   Source File: SqlTypeUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static RelDataType createMapType(
    RelDataTypeFactory typeFactory,
    RelDataType keyType,
    RelDataType valueType,
    boolean nullable) {
  RelDataType ret = typeFactory.createMapType(keyType, valueType);
  return typeFactory.createTypeWithNullability(ret, nullable);
}
 
Example 15
Source Project: Bats   Source File: View.java    License: Apache License 2.0 5 votes vote down vote up
private RelDataType getType(Field field, RelDataTypeFactory factory) {
  RelDataType type;
  final SqlTypeName typeName = field.getType();
  final Integer precision = field.getPrecision();
  final Integer scale = field.getScale();

  if (field.isInterval()) {
    type = factory.createSqlIntervalType(field.getIntervalQualifier());
  } else if (precision != null) {
    type = scale != null
        ? factory.createSqlType(typeName, precision, scale)
        : factory.createSqlType(typeName, precision);
  } else if (typeName == SqlTypeName.MAP) {
    if (field.isMapTypesPresent()) {
      type = factory.createMapType(getType(field.getKeyType(), factory), getType(field.getValueType(), factory));
    } else {
       /*
          For older views that doesn't have info about map key and value types,
          chosen type is ANY. Because use of raw MAP type causes creation of
          MAP cast expression that can't be serialized by ExpressionStringBuilder's
          visitCastExpression(CastExpression e, StringBuilder sb) method.
          See DRILL-6944 for more details.
       */
      type = factory.createSqlType(SqlTypeName.ANY);
    }
  } else {
    type = factory.createSqlType(field.getType());
  }

  return field.getIsNullable() ? factory.createTypeWithNullability(type, true) : type;
}
 
Example 16
Source Project: Bats   Source File: Aggregate.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates an AggCallBinding
 *
 * @param typeFactory  Type factory
 * @param aggFunction  Aggregate function
 * @param operands     Data types of operands
 * @param groupCount   Number of columns in the GROUP BY clause
 * @param filter       Whether the aggregate function has a FILTER clause
 */
public AggCallBinding(RelDataTypeFactory typeFactory,
    SqlAggFunction aggFunction, List<RelDataType> operands, int groupCount,
    boolean filter) {
  super(typeFactory, aggFunction);
  this.operands = operands;
  this.groupCount = groupCount;
  this.filter = filter;
  assert operands != null
      : "operands of aggregate call should not be null";
  assert groupCount >= 0
      : "number of group by columns should be greater than zero in "
      + "aggregate call. Got " + groupCount;
}
 
Example 17
Source Project: Bats   Source File: SqlTypeUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Flattens a record type by recursively expanding any fields which are
 * themselves record types. For each record type, a representative null
 * value field is also prepended (with state NULL for a null value and FALSE
 * for non-null), and all component types are asserted to be nullable, since
 * SQL doesn't allow NOT NULL to be specified on attributes.
 *
 * @param typeFactory   factory which should produced flattened type
 * @param recordType    type with possible nesting
 * @param flatteningMap if non-null, receives map from unflattened ordinal
 *                      to flattened ordinal (must have length at least
 *                      recordType.getFieldList().size())
 * @return flattened equivalent
 */
public static RelDataType flattenRecordType(
    RelDataTypeFactory typeFactory,
    RelDataType recordType,
    int[] flatteningMap) {
  if (!recordType.isStruct()) {
    return recordType;
  }
  List<RelDataTypeField> fieldList = new ArrayList<>();
  boolean nested =
      flattenFields(
          typeFactory,
          recordType,
          fieldList,
          flatteningMap);
  if (!nested) {
    return recordType;
  }
  List<RelDataType> types = new ArrayList<>();
  List<String> fieldNames = new ArrayList<>();
  int i = -1;
  for (RelDataTypeField field : fieldList) {
    ++i;
    types.add(field.getType());
    fieldNames.add(field.getName() + "_" + i);
  }
  return typeFactory.createStructType(types, fieldNames);
}
 
Example 18
Source Project: Bats   Source File: AbstractIndexPlanGenerator.java    License: Apache License 2.0 5 votes vote down vote up
protected RelDataType convertRowType(RelDataType origRowType, RelDataTypeFactory typeFactory) {
  if ( getRowKeyIndex(origRowType, origScan)>=0 ) { // row key already present
    return origRowType;
  }
  List<RelDataTypeField> fields = new ArrayList<>();

  fields.addAll(origRowType.getFieldList());
  fields.add(new RelDataTypeFieldImpl(
      ((DbGroupScan)IndexPlanUtils.getGroupScan(origScan)).getRowKeyName(), fields.size(),
          typeFactory.createSqlType(SqlTypeName.ANY)));
  return new RelRecordType(fields);
}
 
Example 19
Source Project: Bats   Source File: ExplicitOperatorBinding.java    License: Apache License 2.0 5 votes vote down vote up
private ExplicitOperatorBinding(
    SqlOperatorBinding delegate,
    RelDataTypeFactory typeFactory,
    SqlOperator operator,
    List<RelDataType> types) {
  super(typeFactory, operator);
  this.types = types;
  this.delegate = delegate;
}
 
Example 20
Source Project: calcite   Source File: SqlToRelTestBase.java    License: Apache License 2.0 5 votes vote down vote up
public Prepare.CatalogReader createCatalogReader(
    RelDataTypeFactory typeFactory) {
  MockCatalogReader catalogReader;
  if (this.catalogReaderFactory != null) {
    catalogReader = catalogReaderFactory.create(typeFactory, true);
  } else {
    catalogReader = new MockCatalogReaderSimple(typeFactory, true);
  }
  return catalogReader.init();
}
 
Example 21
Source Project: calcite   Source File: SqlValidatorUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the type the row which results when two relations are joined.
 *
 * <p>The resulting row type consists of
 * the system fields (if any), followed by
 * the fields of the left type, followed by
 * the fields of the right type. The field name list, if present, overrides
 * the original names of the fields.
 *
 * @param typeFactory     Type factory
 * @param leftType        Type of left input to join
 * @param rightType       Type of right input to join, or null for semi-join
 * @param fieldNameList   If not null, overrides the original names of the
 *                        fields
 * @param systemFieldList List of system fields that will be prefixed to
 *                        output row type; typically empty but must not be
 *                        null
 * @return type of row which results when two relations are joined
 */
public static RelDataType createJoinType(
    RelDataTypeFactory typeFactory,
    RelDataType leftType,
    RelDataType rightType,
    List<String> fieldNameList,
    List<RelDataTypeField> systemFieldList) {
  assert (fieldNameList == null)
      || (fieldNameList.size()
      == (systemFieldList.size()
      + leftType.getFieldCount()
      + rightType.getFieldCount()));
  List<String> nameList = new ArrayList<>();
  final List<RelDataType> typeList = new ArrayList<>();

  // Use a set to keep track of the field names; this is needed
  // to ensure that the contains() call to check for name uniqueness
  // runs in constant time; otherwise, if the number of fields is large,
  // doing a contains() on a list can be expensive.
  final Set<String> uniqueNameList =
      typeFactory.getTypeSystem().isSchemaCaseSensitive()
          ? new HashSet<>()
          : new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
  addFields(systemFieldList, typeList, nameList, uniqueNameList);
  addFields(leftType.getFieldList(), typeList, nameList, uniqueNameList);
  if (rightType != null) {
    addFields(
        rightType.getFieldList(), typeList, nameList, uniqueNameList);
  }
  if (fieldNameList != null) {
    assert fieldNameList.size() == nameList.size();
    nameList = fieldNameList;
  }
  return typeFactory.createStructType(typeList, nameList);
}
 
Example 22
Source Project: calcite   Source File: JsonTable.java    License: Apache License 2.0 5 votes vote down vote up
/** Returns the data list of the table. */
public List<Object> getDataList(RelDataTypeFactory typeFactory) {
  if (dataList == null) {
    JsonDataConverter jsonDataConverter =
        JsonEnumerator.deduceRowType(typeFactory, source);
    dataList = jsonDataConverter.getDataList();
  }
  return dataList;
}
 
Example 23
Source Project: kylin   Source File: KylinRelDataTypeSystemTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testLegalDecimalType() {
    RelDataTypeSystem typeSystem = new KylinRelDataTypeSystem();
    RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(typeSystem);
    
    DataType dataType = DataType.getType("decimal(30, 10)");
    RelDataType relDataType = OLAPTable.createSqlType(typeFactory, dataType, true);
    
    Assert.assertTrue(relDataType instanceof BasicSqlType);
    Assert.assertEquals(relDataType.getSqlTypeName(), SqlTypeName.DECIMAL);
    Assert.assertEquals(relDataType.getPrecision(), 30);
    Assert.assertTrue(relDataType.getPrecision() <= typeSystem.getMaxNumericPrecision());
    Assert.assertEquals(relDataType.getScale(), 10);
    Assert.assertTrue(relDataType.getScale() <= typeSystem.getMaxNumericScale());
}
 
Example 24
Source Project: calcite   Source File: SchemaNamespace.java    License: Apache License 2.0 5 votes vote down vote up
protected RelDataType validateImpl(RelDataType targetRowType) {
  final RelDataTypeFactory.Builder builder =
      validator.getTypeFactory().builder();
  for (SqlMoniker moniker
      : validator.catalogReader.getAllSchemaObjectNames(names)) {
    final List<String> names1 = moniker.getFullyQualifiedNames();
    final SqlValidatorTable table = validator.catalogReader.getTable(names1);
    builder.add(Util.last(names1), table.getRowType());
  }
  return builder.build();
}
 
Example 25
Source Project: marble   Source File: HiveSqlUDAFReturnTypeInference.java    License: Apache License 2.0 5 votes vote down vote up
@Override public RelDataType inferReturnType(
    final SqlOperatorBinding opBinding) {
  try {
    RelDataTypeFactory factory = opBinding.getTypeFactory();
    SqlOperator sqlOperator = opBinding.getOperator();
    String opName = sqlOperator.getName();
    Class hiveUDAFClass = HiveSqlOperatorTable.instance()
        .getHiveUDAFClass(opName);
    List<RelDataTypeHolder> argsType = new ArrayList<>();

    for (int i = 0; i < opBinding.getOperandCount(); i++) {
      RelDataTypeHolder relDataTypeHolder;
      if (TypeInferenceUtil.isOperandConstantForHiveUDAF(hiveUDAFClass, i)) {
        //we use a pre-defined fake value here to getGenericUDAFReturnType
        Object constantValue = TypeInferenceUtil
            .HIVE_UDAF_CONSTANT_OBJECT_INSPECT_CONTEXT_MAP
            .get(hiveUDAFClass).get(i);
        relDataTypeHolder = new RelDataTypeHolder(opBinding.getOperandType(i),
            true, constantValue);
      } else {
        relDataTypeHolder = new RelDataTypeHolder(
            opBinding.getOperandType(i));
      }
      argsType.add(relDataTypeHolder);
    }
    RelDataType resultType = getGenericUDAFReturnType(
        hiveUDAFClass,
        argsType.toArray(new RelDataTypeHolder[0]), factory);
    return resultType;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 26
Source Project: Bats   Source File: Schemas.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean matches(RelDataTypeFactory typeFactory,
    Function member, List<RelDataType> argumentTypes) {
  List<FunctionParameter> parameters = member.getParameters();
  if (parameters.size() != argumentTypes.size()) {
    return false;
  }
  for (int i = 0; i < argumentTypes.size(); i++) {
    RelDataType argumentType = argumentTypes.get(i);
    FunctionParameter parameter = parameters.get(i);
    if (!canConvert(argumentType, parameter.getType(typeFactory))) {
      return false;
    }
  }
  return true;
}
 
Example 27
Source Project: calcite   Source File: Interpreter.java    License: Apache License 2.0 5 votes vote down vote up
public RelDataType combinedRowType(List<RelNode> inputs) {
  final RelDataTypeFactory.Builder builder =
      interpreter.dataContext.getTypeFactory().builder();
  for (RelNode input : inputs) {
    builder.addAll(input.getRowType().getFieldList());
  }
  return builder.build();
}
 
Example 28
Source Project: Bats   Source File: TypeInferenceUtils.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
  final RelDataTypeFactory factory = opBinding.getTypeFactory();
  final boolean isNullable = opBinding.getOperandType(0).isNullable();
  return createCalciteTypeWithNullability(
      factory,
      SqlTypeName.DOUBLE,
      isNullable);
}
 
Example 29
Source Project: flink   Source File: RelOptCluster.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a cluster.
 */
@Deprecated // to be removed before 2.0
RelOptCluster(
		RelOptQuery query,
		RelOptPlanner planner,
		RelDataTypeFactory typeFactory,
		RexBuilder rexBuilder) {
	this(planner, typeFactory, rexBuilder, query.nextCorrel,
			query.mapCorrelToRel);
}
 
Example 30
Source Project: dremio-oss   Source File: TypeInferenceUtils.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
  final RelDataTypeFactory factory = opBinding.getTypeFactory();
  final SqlTypeName sqlTypeName = SqlTypeName.VARCHAR;

  for(int i = 0; i < opBinding.getOperandCount(); ++i) {
    if(opBinding.getOperandType(i).isNullable()) {
      return createCalciteTypeWithNullability(factory, sqlTypeName, true, null);
    }
  }

  return createCalciteTypeWithNullability(factory, sqlTypeName, false, null);
}