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

The following examples show how to use org.apache.calcite.rel.type.RelDataTypeFactory#createJavaType() . 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: JSqlTable.java    From kafka-eagle with Apache License 2.0 5 votes vote down vote up
public RelDataType getRowType(RelDataTypeFactory typeFactory) {
	if (dataType == null) {
		RelDataTypeFactory.FieldInfoBuilder fieldInfo = typeFactory.builder();
		for (JSqlMapData.Column column : this.sourceTable.columns) {
			RelDataType sqlType = typeFactory.createJavaType(JSqlMapData.JAVATYPE_MAPPING.get(column.type));
			sqlType = SqlTypeUtil.addCharsetAndCollation(sqlType, typeFactory);
			fieldInfo.add(column.name, sqlType);
		}
		this.dataType = typeFactory.createStructType(fieldInfo);
	}
	return this.dataType;
}
 
Example 2
Source File: RedisTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
public RelDataType getRowType(RelDataTypeFactory typeFactory) {
  if (protoRowType != null) {
    return protoRowType.apply(typeFactory);
  }
  final List<RelDataType> types = new ArrayList<RelDataType>(allFields.size());
  final List<String> names = new ArrayList<String>(allFields.size());

  for (Object key : allFields.keySet()) {
    final RelDataType type = typeFactory.createJavaType(allFields.get(key).getClass());
    names.add(key.toString());
    types.add(type);
  }
  return typeFactory.createStructType(Pair.zip(names, types));
}
 
Example 3
Source File: Smalls.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** A function that generates multiplication table of {@code ncol} columns x
 * {@code nrow} rows. */
public static QueryableTable multiplicationTable(final int ncol,
    final int nrow, Integer offset) {
  final int offs = offset == null ? 0 : offset;
  return new AbstractQueryableTable(Object[].class) {
    public RelDataType getRowType(RelDataTypeFactory typeFactory) {
      final RelDataTypeFactory.Builder builder = typeFactory.builder();
      builder.add("row_name", typeFactory.createJavaType(String.class));
      final RelDataType int_ = typeFactory.createJavaType(int.class);
      for (int i = 1; i <= ncol; i++) {
        builder.add("c" + i, int_);
      }
      return builder.build();
    }

    public Queryable<Object[]> asQueryable(QueryProvider queryProvider,
        SchemaPlus schema, String tableName) {
      final List<Object[]> table = new AbstractList<Object[]>() {
        @Override public Object[] get(int index) {
          Object[] cur = new Object[ncol + 1];
          cur[0] = "row " + index;
          for (int j = 1; j <= ncol; j++) {
            cur[j] = j * (index + 1) + offs;
          }
          return cur;
        }

        @Override public int size() {
          return nrow;
        }
      };
      return Linq4j.asEnumerable(table).asQueryable();
    }
  };
}
 
Example 4
Source File: TableInRootSchemaTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
public RelDataType getRowType(RelDataTypeFactory typeFactory) {
  int columnCount = columnNames.length;
  final List<Pair<String, RelDataType>> columnDesc =
      new ArrayList<>(columnCount);
  for (int i = 0; i < columnCount; i++) {
    final RelDataType colType = typeFactory
        .createJavaType(columnTypes[i]);
    columnDesc.add(Pair.of(columnNames[i], colType));
  }
  return typeFactory.createStructType(columnDesc);
}
 
Example 5
Source File: TraitPropagationTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
PhysTable(RelOptCluster cluster) {
  super(cluster, cluster.traitSet().replace(PHYSICAL).replace(COLLATION));
  RelDataTypeFactory typeFactory = cluster.getTypeFactory();
  final RelDataType stringType = typeFactory.createJavaType(String.class);
  final RelDataType integerType = typeFactory.createJavaType(Integer.class);
  this.rowType = typeFactory.builder().add("s", stringType)
      .add("i", integerType).build();
}
 
Example 6
Source File: ScalarFunctionImpl.java    From Bats with Apache License 2.0 4 votes vote down vote up
public RelDataType getReturnType(RelDataTypeFactory typeFactory) {
  return typeFactory.createJavaType(method.getReturnType());
}
 
Example 7
Source File: SolrSchema.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
RelProtoDataType getRelDataType(String collection) {
  // Temporary type factory, just for the duration of this method. Allowable
  // because we're creating a proto-type, not a type; before being used, the
  // proto-type will be copied into a real type factory.
  final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  final RelDataTypeFactory.Builder fieldInfo = typeFactory.builder();
  Map<String, LukeResponse.FieldInfo> luceneFieldInfoMap = getFieldInfo(collection);

  for(Map.Entry<String, LukeResponse.FieldInfo> entry : luceneFieldInfoMap.entrySet()) {
    LukeResponse.FieldInfo luceneFieldInfo = entry.getValue();

    String luceneFieldType = luceneFieldInfo.getType();
    // SOLR-13414: Luke can return a field definition with no type in rare situations
    if(luceneFieldType == null) {
      continue;
    }

    RelDataType type;
    switch (luceneFieldType) {
      case "string":
        type = typeFactory.createJavaType(String.class);
        break;
      case "tint":
      case "tlong":
      case "int":
      case "long":
      case "pint":
      case "plong":
        type = typeFactory.createJavaType(Long.class);
        break;
      case "tfloat":
      case "tdouble":
      case "float":
      case "double":
      case "pfloat":
      case "pdouble":
        type = typeFactory.createJavaType(Double.class);
        break;
      default:
        type = typeFactory.createJavaType(String.class);
    }

    /*
    EnumSet<FieldFlag> flags = luceneFieldInfo.parseFlags(luceneFieldInfo.getSchema());
    if(flags != null && flags.contains(FieldFlag.MULTI_VALUED)) {
      type = typeFactory.createArrayType(type, -1);
    }
    */

    fieldInfo.add(entry.getKey(), type).nullable(true);
  }
  fieldInfo.add("_query_",typeFactory.createJavaType(String.class));
  fieldInfo.add("score",typeFactory.createJavaType(Double.class));

  return RelDataTypeImpl.proto(fieldInfo.build());
}
 
Example 8
Source File: SnapshotFunctions.java    From mat-calcite-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public RelDataType getReturnType(RelDataTypeFactory typeFactory) {
    return typeFactory.createJavaType(functionMethod.getReturnType());
}
 
Example 9
Source File: SqlAdvisorGetHintsFunction2.java    From calcite with Apache License 2.0 4 votes vote down vote up
public RelDataType getRowType(RelDataTypeFactory typeFactory,
    List<Object> arguments) {
  return typeFactory.createJavaType(SqlAdvisorHint2.class);
}
 
Example 10
Source File: SqlAdvisorGetHintsFunction.java    From calcite with Apache License 2.0 4 votes vote down vote up
public RelDataType getRowType(RelDataTypeFactory typeFactory,
    List<Object> arguments) {
  return typeFactory.createJavaType(SqlAdvisorHint.class);
}
 
Example 11
Source File: AggregateFunctionImpl.java    From calcite with Apache License 2.0 4 votes vote down vote up
public RelDataType getReturnType(RelDataTypeFactory typeFactory) {
  return typeFactory.createJavaType(resultType);
}
 
Example 12
Source File: ScalarFunctionImpl.java    From calcite with Apache License 2.0 4 votes vote down vote up
public RelDataType getReturnType(RelDataTypeFactory typeFactory) {
  return typeFactory.createJavaType(method.getReturnType());
}
 
Example 13
Source File: Smalls.java    From calcite with Apache License 2.0 4 votes vote down vote up
/** A function that generates a table that generates a sequence of
 * {@link IntString} values. */
public static QueryableTable generateStrings(final Integer count) {
  return new AbstractQueryableTable(IntString.class) {
    public RelDataType getRowType(RelDataTypeFactory typeFactory) {
      return typeFactory.createJavaType(IntString.class);
    }

    public <T> Queryable<T> asQueryable(QueryProvider queryProvider,
        SchemaPlus schema, String tableName) {
      BaseQueryable<IntString> queryable =
          new BaseQueryable<IntString>(null, IntString.class, null) {
            public Enumerator<IntString> enumerator() {
              return new Enumerator<IntString>() {
                static final String Z = "abcdefghijklm";

                int i = 0;
                int curI;
                String curS;

                public IntString current() {
                  return new IntString(curI, curS);
                }

                public boolean moveNext() {
                  if (i < count) {
                    curI = i;
                    curS = Z.substring(0, i % Z.length());
                    ++i;
                    return true;
                  } else {
                    return false;
                  }
                }

                public void reset() {
                  i = 0;
                }

                public void close() {
                }
              };
            }
          };
      //noinspection unchecked
      return (Queryable<T>) queryable;
    }
  };
}