Java Code Examples for org.apache.calcite.sql.type.ArraySqlType

The following examples show how to use org.apache.calcite.sql.type.ArraySqlType. 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: kylin-on-parquet-v2   Source File: OLAPProjectRel.java    License: Apache License 2.0 5 votes vote down vote up
private void rewriteProjectForIntersect(RexNode rex, SqlTypeName sqlTypeName, BasicSqlType eleSqlType,
        ArraySqlType arraySqlType, int idx) {
    if (rex.isA(SqlKind.ARRAY_VALUE_CONSTRUCTOR)) { // somethings like ['2012-01-01', '2012-01-02', '2012-01-03']
        List<RexNode> nodeList = ((RexCall) rex).getOperands();
        RexLiteral newNode = null;
        boolean needChange = true;
        List<RexNode> newerList = new ArrayList<>();
        if (!nodeList.isEmpty()) {
            for (RexNode node : nodeList) {
                if (node instanceof RexLiteral) {
                    RexLiteral literal = (RexLiteral) node;
                    if (literal.getTypeName() == sqlTypeName) {
                        needChange = false;
                        break;
                    } else {
                        newNode = RexLiteral.fromJdbcString(eleSqlType, sqlTypeName,
                                literal.getValue2().toString());
                    }
                }
                if (newNode != null) {
                    newerList.add(newNode);
                }
                newNode = null;
            }
            if (needChange) {
                rewriteProjects.set(idx, ((RexCall) rex).clone(arraySqlType, newerList));
                logger.debug("Rewrite project REL {} for intersect count.", rewriteProjects.get(idx));
            }
        }
    }
}
 
Example 2
Source Project: samza   Source File: RelSchemaConverter.java    License: 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 3
Source Project: kylin   Source File: OLAPProjectRel.java    License: Apache License 2.0 5 votes vote down vote up
private void rewriteProjectForIntersect(RexNode rex, SqlTypeName sqlTypeName, BasicSqlType eleSqlType,
        ArraySqlType arraySqlType, int idx) {
    if (rex.isA(SqlKind.ARRAY_VALUE_CONSTRUCTOR)) { // somethings like ['2012-01-01', '2012-01-02', '2012-01-03']
        List<RexNode> nodeList = ((RexCall) rex).getOperands();
        RexLiteral newNode = null;
        boolean needChange = true;
        List<RexNode> newerList = new ArrayList<>();
        if (!nodeList.isEmpty()) {
            for (RexNode node : nodeList) {
                if (node instanceof RexLiteral) {
                    RexLiteral literal = (RexLiteral) node;
                    if (literal.getTypeName() == sqlTypeName) {
                        needChange = false;
                        break;
                    } else {
                        newNode = RexLiteral.fromJdbcString(eleSqlType, sqlTypeName,
                                literal.getValue2().toString());
                    }
                }
                if (newNode != null) {
                    newerList.add(newNode);
                }
                newNode = null;
            }
            if (needChange) {
                rewriteProjects.set(idx, ((RexCall) rex).clone(arraySqlType, newerList));
                logger.debug("Rewrite project REL {} for intersect count.", rewriteProjects.get(idx));
            }
        }
    }
}