Java Code Examples for org.apache.calcite.rel.type.RelDataTypeSystem#DEFAULT

The following examples show how to use org.apache.calcite.rel.type.RelDataTypeSystem#DEFAULT . 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: CalciteCatalogReader.java    From Bats with Apache License 2.0 6 votes vote down vote up
/** Creates an operator table that contains functions in the given class.
   *
   * @see ModelHandler#addFunctions */
  public static SqlOperatorTable operatorTable(String className) {
    // Dummy schema to collect the functions
    final CalciteSchema schema =
        CalciteSchema.createRootSchema(false, false);
//    ModelHandler.addFunctions(schema.plus(), null, ImmutableList.of(),
//        className, "*", true);

    // The following is technical debt; see [CALCITE-2082] Remove
    // RelDataTypeFactory argument from SqlUserDefinedAggFunction constructor
    final SqlTypeFactoryImpl typeFactory =
        new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);

    final ListSqlOperatorTable table = new ListSqlOperatorTable();
    for (String name : schema.getFunctionNames()) {
      for (Function function : schema.getFunctions(name, true)) {
        final SqlIdentifier id = new SqlIdentifier(name, SqlParserPos.ZERO);
        table.add(
            toOp(typeFactory, id, function));
      }
    }
    return table;
  }
 
Example 2
Source File: RexBuilderTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Tests {@link RexBuilder#makeDateLiteral(DateString)}. */
@Test void testDateLiteral() {
  final RelDataTypeFactory typeFactory =
      new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  RelDataType dateType = typeFactory.createSqlType(SqlTypeName.DATE);
  final RexBuilder builder = new RexBuilder(typeFactory);

  // Old way: provide a Calendar
  final Calendar calendar = Util.calendar();
  calendar.set(1969, Calendar.JULY, 21); // one small step
  calendar.set(Calendar.MILLISECOND, 0);
  checkDate(builder.makeLiteral(calendar, dateType, false));

  // Old way #2: Provide in Integer
  checkDate(builder.makeLiteral(MOON_DAY, dateType, false));

  // The new way
  final DateString d = new DateString(1969, 7, 21);
  checkDate(builder.makeLiteral(d, dateType, false));
}
 
Example 3
Source File: RexBuilderTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Tests {@link RexCopier#visitRangeRef(RexRangeRef)} */
@Test void testCopyRangeRef() {
  final RelDataTypeFactory sourceTypeFactory =
      new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  RelDataType type = sourceTypeFactory.createSqlType(SqlTypeName.VARCHAR, 65536);

  final RelDataTypeFactory targetTypeFactory =
      new MySqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  final RexBuilder builder = new RexBuilder(targetTypeFactory);

  final RexRangeRef node = builder.makeRangeReference(type, 1, true);
  final RexNode copy = builder.copy(node);
  assertTrue(copy instanceof RexRangeRef);

  final RexRangeRef result = (RexRangeRef) copy;
  assertThat(result.getOffset(), is(node.getOffset()));
  assertThat(result.getType().getSqlTypeName(), is(SqlTypeName.VARCHAR));
  assertThat(result.getType().getPrecision(), is(PRECISION));
}
 
Example 4
Source File: CalciteCatalogReader.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Creates an operator table that contains functions in the given class.
 *
 * @see ModelHandler#addFunctions */
public static SqlOperatorTable operatorTable(String className) {
  // Dummy schema to collect the functions
  final CalciteSchema schema =
      CalciteSchema.createRootSchema(false, false);
  ModelHandler.addFunctions(schema.plus(), null, ImmutableList.of(),
      className, "*", true);

  // The following is technical debt; see [CALCITE-2082] Remove
  // RelDataTypeFactory argument from SqlUserDefinedAggFunction constructor
  final SqlTypeFactoryImpl typeFactory =
      new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);

  final ListSqlOperatorTable table = new ListSqlOperatorTable();
  for (String name : schema.getFunctionNames()) {
    for (Function function : schema.getFunctions(name, true)) {
      final SqlIdentifier id = new SqlIdentifier(name, SqlParserPos.ZERO);
      table.add(
          toOp(typeFactory, id, function));
    }
  }
  return table;
}
 
Example 5
Source File: GeodeEnumerator.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a GeodeEnumerator.
 *
 * @param results      Geode result set ({@link SelectResults})
 * @param protoRowType The type of resulting rows
 */
GeodeEnumerator(SelectResults results, RelProtoDataType protoRowType) {
  if (results == null) {
    LOGGER.warn("Null OQL results!");
  }
  this.iterator = (results == null) ? Collections.emptyIterator() : results.iterator();
  this.current = null;

  final RelDataTypeFactory typeFactory =
      new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  this.fieldTypes = protoRowType.apply(typeFactory).getFieldList();
}
 
Example 6
Source File: ArrayTableTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** As {@link #testLoadSorted()} but column #1 is the unique column, not
 * column #0. The algorithm needs to go back and permute the values of
 * column #0 after it discovers that column #1 is unique and sorts by it. */
@Test void testLoadSorted2() {
  final JavaTypeFactoryImpl typeFactory =
      new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  final RelDataType rowType =
      typeFactory.builder()
          .add("deptno", typeFactory.createType(int.class))
          .add("empid", typeFactory.createType(int.class))
          .add("name", typeFactory.createType(String.class))
          .build();
  final Enumerable<Object[]> enumerable =
      Linq4j.asEnumerable(
          Arrays.asList(
              new Object[]{10, 100, "Bill"},
              new Object[]{20, 200, "Eric"},
              new Object[]{30, 150, "Sebastian"},
              new Object[]{10, 160, "Theodore"}));
  final ColumnLoader<Object[]> loader =
      new ColumnLoader<Object[]>(typeFactory, enumerable,
          RelDataTypeImpl.proto(rowType), null);
  // Note that values have been sorted with {20, 200, Eric} last because the
  // value 200 is the highest value of empid, the unique column.
  checkColumn(
      loader.representationValues.get(0),
      ArrayTable.RepresentationType.BIT_SLICED_PRIMITIVE_ARRAY,
      "Column(representation=BitSlicedPrimitiveArray(ordinal=0, bitCount=5, primitive=INT, signed=false), value=[10, 30, 10, 20, 0, 0, 0, 0, 0, 0, 0, 0])");
  checkColumn(
      loader.representationValues.get(1),
      ArrayTable.RepresentationType.BIT_SLICED_PRIMITIVE_ARRAY,
      "Column(representation=BitSlicedPrimitiveArray(ordinal=1, bitCount=8, primitive=INT, signed=false), value=[100, 150, 160, 200, 0, 0, 0, 0])");
  checkColumn(
      loader.representationValues.get(2),
      ArrayTable.RepresentationType.OBJECT_ARRAY,
      "Column(representation=ObjectArray(ordinal=2), value=[Bill, Sebastian, Theodore, Eric])");
}
 
Example 7
Source File: ArrayTableTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Test void testLoadSorted() {
  final JavaTypeFactoryImpl typeFactory =
      new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  final RelDataType rowType =
      typeFactory.builder()
          .add("empid", typeFactory.createType(int.class))
          .add("deptno", typeFactory.createType(int.class))
          .add("name", typeFactory.createType(String.class))
          .build();
  final Enumerable<Object[]> enumerable =
      Linq4j.asEnumerable(
          Arrays.asList(
              new Object[]{100, 10, "Bill"},
              new Object[]{200, 20, "Eric"},
              new Object[]{150, 10, "Sebastian"},
              new Object[]{160, 10, "Theodore"}));
  final ColumnLoader<Object[]> loader =
      new ColumnLoader<Object[]>(typeFactory, enumerable,
          RelDataTypeImpl.proto(rowType), null);
  checkColumn(
      loader.representationValues.get(0),
      ArrayTable.RepresentationType.BIT_SLICED_PRIMITIVE_ARRAY,
      "Column(representation=BitSlicedPrimitiveArray(ordinal=0, bitCount=8, primitive=INT, signed=false), value=[100, 150, 160, 200, 0, 0, 0, 0])");
  checkColumn(
      loader.representationValues.get(1),
      ArrayTable.RepresentationType.BIT_SLICED_PRIMITIVE_ARRAY,
      "Column(representation=BitSlicedPrimitiveArray(ordinal=1, bitCount=5, primitive=INT, signed=false), value=[10, 10, 10, 20, 0, 0, 0, 0, 0, 0, 0, 0])");
  checkColumn(
      loader.representationValues.get(2),
      ArrayTable.RepresentationType.OBJECT_ARRAY,
      "Column(representation=ObjectArray(ordinal=2), value=[Bill, Sebastian, Theodore, Eric])");
}
 
Example 8
Source File: SqlOperatorBindingTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setUp() {
  JavaTypeFactory typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  integerDataType = typeFactory.createSqlType(SqlTypeName.INTEGER);
  integerType = SqlTypeUtil.convertTypeToSpec(integerDataType);
  rexBuilder = new RexBuilder(typeFactory);
}
 
Example 9
Source File: RexBuilderTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Test RexBuilder.ensureType()
 */
@Test void testEnsureTypeWithAny() {
  final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  RexBuilder builder = new RexBuilder(typeFactory);

  RexNode node =  new RexLiteral(
          Boolean.TRUE, typeFactory.createSqlType(SqlTypeName.BOOLEAN), SqlTypeName.BOOLEAN);
  RexNode ensuredNode = builder.ensureType(
          typeFactory.createSqlType(SqlTypeName.ANY), node, true);

  assertEquals(node, ensuredNode);
}
 
Example 10
Source File: KafkaRowConverterImpl.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Generate row schema for a given Kafka topic.
 *
 * @param topicName, Kafka topic name;
 * @return row type
 */
@Override public RelDataType rowDataType(final String topicName) {
  final RelDataTypeFactory typeFactory =
      new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  final RelDataTypeFactory.Builder fieldInfo = typeFactory.builder();
  fieldInfo.add("MSG_PARTITION", typeFactory.createSqlType(SqlTypeName.INTEGER)).nullable(false);
  fieldInfo.add("MSG_TIMESTAMP", typeFactory.createSqlType(SqlTypeName.BIGINT)).nullable(false);
  fieldInfo.add("MSG_OFFSET", typeFactory.createSqlType(SqlTypeName.BIGINT)).nullable(false);
  fieldInfo.add("MSG_KEY_BYTES", typeFactory.createSqlType(SqlTypeName.VARBINARY)).nullable(true);
  fieldInfo.add("MSG_VALUE_BYTES", typeFactory.createSqlType(SqlTypeName.VARBINARY))
      .nullable(false);

  return fieldInfo.build();
}
 
Example 11
Source File: TestCompilerUtils.java    From streamline with Apache License 2.0 5 votes vote down vote up
public static CalciteState sqlOverDummyTable(String sql)
        throws RelConversionException, ValidationException, SqlParseException {
    SchemaPlus schema = Frameworks.createRootSchema(true);
    JavaTypeFactory typeFactory = new JavaTypeFactoryImpl
            (RelDataTypeSystem.DEFAULT);
    StreamableTable streamableTable = new CompilerUtil.TableBuilderInfo(typeFactory)
            .field("ID", SqlTypeName.INTEGER)
            .field("NAME", typeFactory.createType(String.class))
            .field("ADDR", typeFactory.createType(String.class))
            .build();
    Table table = streamableTable.stream();
    schema.add("FOO", table);
    schema.add("BAR", table);
    schema.add("MYPLUS", ScalarFunctionImpl.create(MyPlus.class, "eval"));

    List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>();
    sqlOperatorTables.add(SqlStdOperatorTable.instance());
    sqlOperatorTables.add(new CalciteCatalogReader(CalciteSchema.from(schema),
            false,
            Collections.<String>emptyList(), typeFactory));
    SqlOperatorTable chainedSqlOperatorTable = new ChainedSqlOperatorTable(sqlOperatorTables);
    FrameworkConfig config = Frameworks.newConfigBuilder().defaultSchema(
            schema).operatorTable(chainedSqlOperatorTable).build();
    Planner planner = Frameworks.getPlanner(config);
    SqlNode parse = planner.parse(sql);
    SqlNode validate = planner.validate(parse);
    RelNode tree = planner.convert(validate);
    System.out.println(RelOptUtil.toString(tree, SqlExplainLevel.ALL_ATTRIBUTES));
    return new CalciteState(schema, tree);
}
 
Example 12
Source File: RelOptUtilTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Test void testTypeDump() {
  RelDataTypeFactory typeFactory =
      new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  RelDataType t1 =
      typeFactory.builder()
          .add("f0", SqlTypeName.DECIMAL, 5, 2)
          .add("f1", SqlTypeName.VARCHAR, 10)
          .build();
  TestUtil.assertEqualsVerbose(
      TestUtil.fold(
          "f0 DECIMAL(5, 2) NOT NULL,",
          "f1 VARCHAR(10) NOT NULL"),
      Util.toLinux(RelOptUtil.dumpType(t1) + "\n"));

  RelDataType t2 =
      typeFactory.builder()
          .add("f0", t1)
          .add("f1", typeFactory.createMultisetType(t1, -1))
          .build();
  TestUtil.assertEqualsVerbose(
      TestUtil.fold(
          "f0 RECORD (",
          "  f0 DECIMAL(5, 2) NOT NULL,",
          "  f1 VARCHAR(10) NOT NULL) NOT NULL,",
          "f1 RECORD (",
          "  f0 DECIMAL(5, 2) NOT NULL,",
          "  f1 VARCHAR(10) NOT NULL) NOT NULL MULTISET NOT NULL"),
      Util.toLinux(RelOptUtil.dumpType(t2) + "\n"));
}
 
Example 13
Source File: RexBuilderTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Tests {@link RexCopier#visitOver(RexOver)} */
@Test void testCopyOver() {
  final RelDataTypeFactory sourceTypeFactory =
      new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  RelDataType type = sourceTypeFactory.createSqlType(SqlTypeName.VARCHAR, 65536);

  final RelDataTypeFactory targetTypeFactory =
      new MySqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  final RexBuilder builder = new RexBuilder(targetTypeFactory);

  final RexOver node = (RexOver) builder.makeOver(type,
      SqlStdOperatorTable.COUNT,
      ImmutableList.of(builder.makeInputRef(type, 0)),
      ImmutableList.of(builder.makeInputRef(type, 1)),
      ImmutableList.of(
          new RexFieldCollation(
              builder.makeInputRef(type, 2), ImmutableSet.of())),
      RexWindowBounds.UNBOUNDED_PRECEDING,
      RexWindowBounds.CURRENT_ROW,
      true, true, false, false, false);
  final RexNode copy = builder.copy(node);
  assertTrue(copy instanceof RexOver);

  RexOver result = (RexOver) copy;
  assertThat(result.getType().getSqlTypeName(), is(SqlTypeName.VARCHAR));
  assertThat(result.getType().getPrecision(), is(PRECISION));
  assertThat(result.getWindow(), is(node.getWindow()));
  assertThat(result.getAggOperator(), is(node.getAggOperator()));
  assertThat(result.getAggOperator(), is(node.getAggOperator()));
  assertEquals(node.isDistinct(), result.isDistinct());
  assertEquals(node.ignoreNulls(), result.ignoreNulls());
  for (int i = 0; i < node.getOperands().size(); i++) {
    assertThat(result.getOperands().get(i).getType().getSqlTypeName(),
        is(node.getOperands().get(i).getType().getSqlTypeName()));
    assertThat(result.getOperands().get(i).getType().getPrecision(),
        is(PRECISION));
  }
}
 
Example 14
Source File: BatsOptimizerTest.java    From Bats with Apache License 2.0 4 votes vote down vote up
static JavaTypeFactory createJavaTypeFactory() {
    RelDataTypeSystem relDataTypeSystem = RelDataTypeSystem.DEFAULT;
    JavaTypeFactoryImpl javaTypeFactory = new JavaTypeFactoryImpl(relDataTypeSystem);
    return javaTypeFactory;
}
 
Example 15
Source File: RexBuilderTest.java    From calcite with Apache License 2.0 4 votes vote down vote up
/** Tests {@link RexBuilder#makeTimestampLiteral(TimestampString, int)}. */
@Test void testTimestampLiteral() {
  final RelDataTypeFactory typeFactory =
      new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  final RelDataType timestampType =
      typeFactory.createSqlType(SqlTypeName.TIMESTAMP);
  final RelDataType timestampType3 =
      typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 3);
  final RelDataType timestampType9 =
      typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 9);
  final RelDataType timestampType18 =
      typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 18);
  final RexBuilder builder = new RexBuilder(typeFactory);

  // Old way: provide a Calendar
  final Calendar calendar = Util.calendar();
  calendar.set(1969, Calendar.JULY, 21, 2, 56, 15); // one small step
  calendar.set(Calendar.MILLISECOND, 0);
  checkTimestamp(builder.makeLiteral(calendar, timestampType, false));

  // Old way #2: Provide a Long
  checkTimestamp(builder.makeLiteral(MOON, timestampType, false));

  // The new way
  final TimestampString ts = new TimestampString(1969, 7, 21, 2, 56, 15);
  checkTimestamp(builder.makeLiteral(ts, timestampType, false));

  // Now with milliseconds
  final TimestampString ts2 = ts.withMillis(56);
  assertThat(ts2.toString(), is("1969-07-21 02:56:15.056"));
  final RexNode literal2 = builder.makeLiteral(ts2, timestampType3, false);
  assertThat(((RexLiteral) literal2).getValueAs(TimestampString.class)
          .toString(), is("1969-07-21 02:56:15.056"));

  // Now with nanoseconds
  final TimestampString ts3 = ts.withNanos(56);
  final RexNode literal3 = builder.makeLiteral(ts3, timestampType9, false);
  assertThat(((RexLiteral) literal3).getValueAs(TimestampString.class)
          .toString(), is("1969-07-21 02:56:15"));
  final TimestampString ts3b = ts.withNanos(2345678);
  final RexNode literal3b = builder.makeLiteral(ts3b, timestampType9, false);
  assertThat(((RexLiteral) literal3b).getValueAs(TimestampString.class)
          .toString(), is("1969-07-21 02:56:15.002"));

  // Now with a very long fraction
  final TimestampString ts4 = ts.withFraction("102030405060708090102");
  final RexNode literal4 = builder.makeLiteral(ts4, timestampType18, false);
  assertThat(((RexLiteral) literal4).getValueAs(TimestampString.class)
          .toString(), is("1969-07-21 02:56:15.102"));

  // toString
  assertThat(ts2.round(1).toString(), is("1969-07-21 02:56:15"));
  assertThat(ts2.round(2).toString(), is("1969-07-21 02:56:15.05"));
  assertThat(ts2.round(3).toString(), is("1969-07-21 02:56:15.056"));
  assertThat(ts2.round(4).toString(), is("1969-07-21 02:56:15.056"));

  assertThat(ts2.toString(6), is("1969-07-21 02:56:15.056000"));
  assertThat(ts2.toString(1), is("1969-07-21 02:56:15.0"));
  assertThat(ts2.toString(0), is("1969-07-21 02:56:15"));

  assertThat(ts2.round(0).toString(), is("1969-07-21 02:56:15"));
  assertThat(ts2.round(0).toString(0), is("1969-07-21 02:56:15"));
  assertThat(ts2.round(0).toString(1), is("1969-07-21 02:56:15.0"));
  assertThat(ts2.round(0).toString(2), is("1969-07-21 02:56:15.00"));

  assertThat(TimestampString.fromMillisSinceEpoch(1456513560123L).toString(),
      is("2016-02-26 19:06:00.123"));
}
 
Example 16
Source File: MatchTest.java    From calcite with Apache License 2.0 4 votes vote down vote up
/**
 * Tests the ElasticSearch match query. The match query is translated from
 * CONTAINS query which is build using RelBuilder, RexBuilder because the
 * normal SQL query assumes CONTAINS query is for date/period range.
 *
 * <p>Equivalent SQL query:
 *
 * <blockquote>
 * <code>select * from zips where city contains 'waltham'</code>
 * </blockquote>
 *
 * <p>ElasticSearch query for it:
 *
 * <blockquote><code>
 * {"query":{"constant_score":{"filter":{"match":{"city":"waltham"}}}}}
 * </code></blockquote>
 */
@Test void testMatchQuery() throws Exception {

  CalciteConnection con = (CalciteConnection) newConnectionFactory()
      .createConnection();
  SchemaPlus postSchema = con.getRootSchema().getSubSchema("elastic");

  FrameworkConfig postConfig = Frameworks.newConfigBuilder()
      .parserConfig(SqlParser.Config.DEFAULT)
      .defaultSchema(postSchema)
      .build();

  final RelBuilder builder = RelBuilder.create(postConfig);
  builder.scan(ZIPS);

  final RelDataTypeFactory typeFactory =
      new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  final RexBuilder rexBuilder = new RexBuilder(typeFactory);

  RexNode nameRexNode = rexBuilder.makeCall(SqlStdOperatorTable.ITEM,
      rexBuilder.makeInputRef(typeFactory.createSqlType(SqlTypeName.ANY), 0),
      rexBuilder.makeCharLiteral(
          new NlsString("city", typeFactory.getDefaultCharset().name(),
              SqlCollation.COERCIBLE)));

  RelDataType mapType = typeFactory.createMapType(
      typeFactory.createSqlType(SqlTypeName.VARCHAR),
      typeFactory.createTypeWithNullability(
          typeFactory.createSqlType(SqlTypeName.ANY), true));

  List<RexNode> namedList =
      ImmutableList.of(rexBuilder.makeInputRef(mapType, 0),
          nameRexNode);

  // Add fields in builder stack so it is accessible while filter preparation
  builder.projectNamed(namedList, Arrays.asList("_MAP", "city"), true);

  RexNode filterRexNode = builder
      .call(SqlStdOperatorTable.CONTAINS, builder.field("city"),
          builder.literal("waltham"));
  builder.filter(filterRexNode);

  String builderExpected = ""
      + "LogicalFilter(condition=[CONTAINS($1, 'waltham')])\n"
      + "  LogicalProject(_MAP=[$0], city=[ITEM($0, 'city')])\n"
      + "    ElasticsearchTableScan(table=[[elastic, " + ZIPS + "]])\n";

  RelNode root = builder.build();

  RelRunner ru = (RelRunner) con.unwrap(Class.forName("org.apache.calcite.tools.RelRunner"));
  try (PreparedStatement preparedStatement = ru.prepare(root)) {

    String s = CalciteAssert.toString(preparedStatement.executeQuery());
    final String result = ""
        + "_MAP={id=02154, city=NORTH WALTHAM, loc=[-71.236497, 42.382492], "
        + "pop=57871, state=MA}; city=NORTH WALTHAM\n";

    // Validate query prepared
    assertThat(root, hasTree(builderExpected));

    // Validate result returned from ES
    assertThat(s, is(result));
  }
}
 
Example 17
Source File: MockCatalogReader.java    From calcite with Apache License 2.0 4 votes vote down vote up
MockDynamicTable(String catalogName, String schemaName, String name) {
  super(Object.class);
  this.names = Arrays.asList(catalogName, schemaName, name);
  this.rowType = new DynamicRecordTypeImpl(new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT));
}
 
Example 18
Source File: RelSchemaConverter.java    From samza with Apache License 2.0 4 votes vote down vote up
public RelSchemaConverter() {
  super(RelDataTypeSystem.DEFAULT);
}
 
Example 19
Source File: SamzaSqlJavaTypeFactoryImpl.java    From samza with Apache License 2.0 4 votes vote down vote up
public SamzaSqlJavaTypeFactoryImpl() {
  this(RelDataTypeSystem.DEFAULT);
}
 
Example 20
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());
}