org.apache.calcite.avatica.ColumnMetaData Java Examples

The following examples show how to use org.apache.calcite.avatica.ColumnMetaData. 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: QuarkMetaImpl.java    From quark with Apache License 2.0 6 votes vote down vote up
protected MetaResultSet createResultSet(
    Map<String, Object> internalParameters, List<ColumnMetaData> columns,
    CursorFactory cursorFactory, final Frame firstFrame) {
  try {
    final QuarkConnectionImpl connection = getConnection();
    final AvaticaStatement statement = connection.createStatement();
    final CalcitePrepare.CalciteSignature<Object> signature =
        new CalcitePrepare.CalciteSignature<Object>("",
            ImmutableList.<AvaticaParameter>of(), internalParameters, null,
            columns, cursorFactory, null, ImmutableList.<RelCollation>of(), -1,
            null, Meta.StatementType.SELECT) {
          @Override public Enumerable<Object> enumerable(
              DataContext dataContext) {
            return Linq4j.asEnumerable(firstFrame.rows);
          }
        };
    return MetaResultSet.create(connection.id, statement.getId(), true,
        signature, firstFrame);
  } catch (SQLException e) {
    throw new RuntimeException(e);
  }
}
 
Example #2
Source File: CalciteResultSet.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public ResultSet create(ColumnMetaData.AvaticaType elementType,
    Iterable<Object> iterable) throws SQLException {
  final List<ColumnMetaData> columnMetaDataList;
  if (elementType instanceof ColumnMetaData.StructType) {
    columnMetaDataList = ((ColumnMetaData.StructType) elementType).columns;
  } else {
    columnMetaDataList =
        ImmutableList.of(ColumnMetaData.dummy(elementType, false));
  }
  final CalcitePrepare.CalciteSignature signature =
      (CalcitePrepare.CalciteSignature) this.signature;
  final CalcitePrepare.CalciteSignature<Object> newSignature =
      new CalcitePrepare.CalciteSignature<>(signature.sql,
          signature.parameters, signature.internalParameters,
          signature.rowType, columnMetaDataList, Meta.CursorFactory.ARRAY,
          signature.rootSchema, ImmutableList.of(), -1, null,
          statement.getStatementType());
  ResultSetMetaData subResultSetMetaData =
      new AvaticaResultSetMetaData(statement, null, newSignature);
  final CalciteResultSet resultSet =
      new CalciteResultSet(statement, signature, subResultSetMetaData,
          localCalendar.getTimeZone(), new Meta.Frame(0, true, iterable));
  final Cursor cursor = resultSet.createCursor(elementType, iterable);
  return resultSet.execute2(cursor, columnMetaDataList);
}
 
Example #3
Source File: DremioColumnMetaDataListTest.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Test
public void testIterator() throws Exception {
  assertFalse(emptyList.iterator().hasNext());

  Iterator<ColumnMetaData> iterator1 = oneElementList.iterator();
  assertNotNull(iterator1);
  assertTrue(iterator1.hasNext());
  assertEquals(iterator1.next(), oneElementList.get(0));
  assertFalse(iterator1.hasNext());

  Iterator<ColumnMetaData> iterator2 = twoElementList.iterator();
  assertNotNull(iterator2);
  assertTrue(iterator2.hasNext());
  assertEquals(iterator2.next(), twoElementList.get(0));
  assertTrue(iterator2.hasNext());
  assertEquals(iterator2.next(), twoElementList.get(1));
  assertFalse(iterator2.hasNext());
}
 
Example #4
Source File: ColumnLoader.java    From Quicksql with MIT License 6 votes vote down vote up
/** Creates a column loader, and performs the load.
 *
 * @param typeFactory Type factory
 * @param sourceTable Source data
 * @param protoRowType Logical row type
 * @param repList Physical row types, or null if not known */
ColumnLoader(JavaTypeFactory typeFactory,
    Enumerable<T> sourceTable,
    RelProtoDataType protoRowType,
    List<ColumnMetaData.Rep> repList) {
  this.typeFactory = typeFactory;
  final RelDataType rowType = protoRowType.apply(typeFactory);
  if (repList == null) {
    repList =
        Collections.nCopies(rowType.getFieldCount(),
            ColumnMetaData.Rep.OBJECT);
  }
  sourceTable.into(list);
  final int[] sorts = {-1};
  load(rowType, repList, sorts);
  this.sortField = sorts[0];
}
 
Example #5
Source File: DruidConnectionImpl.java    From Quicksql with MIT License 6 votes vote down vote up
/** Executes a query request.
     *
     * @param queryType Query type
     * @param data Data to post
     * @param sink Sink to which to send the parsed rows
     * @param fieldNames Names of fields
     * @param fieldTypes Types of fields (never null, but elements may be null)
     * @param page Page definition (in/out)
     */
    public void request(QueryType queryType, String data, Sink sink,
        List<String> fieldNames, List<ColumnMetaData.Rep> fieldTypes,
        Page page) {
        final String url = this.url + "/druid/v2/?pretty";
        final Map<String, String> requestHeaders =
            ImmutableMap.of("Content-Type", "application/json");
//        if (CalcitePrepareImpl.DEBUG) {
//            System.out.println(data);
//        }
        try (InputStream in0 = post(url, data, requestHeaders, 10000, 1800000);
            InputStream in = traceResponse(in0)) {
            parse(queryType, in, sink, fieldNames, fieldTypes, page);
        } catch (IOException e) {
            throw new RuntimeException("Error while processing druid request ["
                + data + "]", e);
        }
    }
 
Example #6
Source File: DruidConnectionImpl.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Executes a query request.
 *
 * @param queryType Query type
 * @param data Data to post
 * @param sink Sink to which to send the parsed rows
 * @param fieldNames Names of fields
 * @param fieldTypes Types of fields (never null, but elements may be null)
 * @param page Page definition (in/out)
 */
public void request(QueryType queryType, String data, Sink sink,
    List<String> fieldNames, List<ColumnMetaData.Rep> fieldTypes,
    Page page) {
  final String url = this.url + "/druid/v2/?pretty";
  final Map<String, String> requestHeaders =
      ImmutableMap.of("Content-Type", "application/json");
  if (CalciteSystemProperty.DEBUG.value()) {
    System.out.println(data);
  }
  try (InputStream in0 = post(url, data, requestHeaders, 10000, 1800000);
       InputStream in = traceResponse(in0)) {
    parse(queryType, in, sink, fieldNames, fieldTypes, page);
  } catch (IOException e) {
    throw new RuntimeException("Error while processing druid request ["
        + data + "]", e);
  }
}
 
Example #7
Source File: ArrayImplTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@Test public void testArrayWithOffsets() throws Exception {
  // Define the struct type we're creating
  ScalarType intType = ColumnMetaData.scalar(Types.INTEGER, "INTEGER", Rep.INTEGER);
  ArrayImpl.Factory factory = new ArrayFactoryImpl(Unsafe.localCalendar().getTimeZone());
  // Create some arrays from the structs
  Array array1 = factory.createArray(intType, Arrays.<Object>asList(1, 2));
  Array array3 = factory.createArray(intType, Arrays.<Object>asList(4, 5, 6));

  Object[] data = (Object[]) array1.getArray(2, 1);
  assertEquals(1, data.length);
  assertEquals(2, data[0]);
  data = (Object[]) array3.getArray(1, 1);
  assertEquals(1, data.length);
  assertEquals(4, data[0]);
  data = (Object[]) array3.getArray(2, 2);
  assertEquals(2, data.length);
  assertEquals(5, data[0]);
  assertEquals(6, data[1]);
  data = (Object[]) array3.getArray(1, 3);
  assertEquals(3, data.length);
  assertEquals(4, data[0]);
  assertEquals(5, data[1]);
  assertEquals(6, data[2]);
}
 
Example #8
Source File: CalciteResultSet.java    From Quicksql with MIT License 6 votes vote down vote up
@Override public ResultSet create(ColumnMetaData.AvaticaType elementType,
    Iterable<Object> iterable) throws SQLException {
  final List<ColumnMetaData> columnMetaDataList;
  if (elementType instanceof ColumnMetaData.StructType) {
    columnMetaDataList = ((ColumnMetaData.StructType) elementType).columns;
  } else {
    columnMetaDataList =
        ImmutableList.of(ColumnMetaData.dummy(elementType, false));
  }
  final CalcitePrepare.CalciteSignature signature =
      (CalcitePrepare.CalciteSignature) this.signature;
  final CalcitePrepare.CalciteSignature<Object> newSignature =
      new CalcitePrepare.CalciteSignature<>(signature.sql,
          signature.parameters, signature.internalParameters,
          signature.rowType, columnMetaDataList, Meta.CursorFactory.ARRAY,
          signature.rootSchema, ImmutableList.of(), -1, null,
          statement.getStatementType());
  ResultSetMetaData subResultSetMetaData =
      new AvaticaResultSetMetaData(statement, null, newSignature);
  final CalciteResultSet resultSet =
      new CalciteResultSet(statement, signature, subResultSetMetaData,
          localCalendar.getTimeZone(), new Meta.Frame(0, true, iterable));
  final Cursor cursor = resultSet.createCursor(elementType, iterable);
  return resultSet.execute2(cursor, columnMetaDataList);
}
 
Example #9
Source File: QuarkResultSet.java    From quark with Apache License 2.0 6 votes vote down vote up
@Override
public ResultSet create(ColumnMetaData.AvaticaType elementType,
                        Iterable<Object> iterable) {
  final List<ColumnMetaData> columnMetaDataList;
  if (elementType instanceof ColumnMetaData.StructType) {
    columnMetaDataList = ((ColumnMetaData.StructType) elementType).columns;
  } else {
    columnMetaDataList =
        ImmutableList.of(ColumnMetaData.dummy(elementType, false));
  }
  final CalcitePrepare.CalciteSignature signature =
      (CalcitePrepare.CalciteSignature) this.signature;
  final CalcitePrepare.CalciteSignature<Object> newSignature =
      new CalcitePrepare.CalciteSignature<>(signature.sql,
          signature.parameters, signature.internalParameters,
          signature.rowType, columnMetaDataList, Meta.CursorFactory.ARRAY,
          signature.rootSchema, ImmutableList.<RelCollation>of(), -1, null);
  ResultSetMetaData subResultSetMetaData =
      new AvaticaResultSetMetaData(statement, null, newSignature);
  final QuarkResultSet resultSet =
      new QuarkResultSet(statement, signature, subResultSetMetaData,
          localCalendar.getTimeZone(), new Meta.Frame(0, true, iterable));
  final Cursor cursor = resultSet.createCursor(elementType, iterable);
  return resultSet.execute2(cursor, columnMetaDataList);
}
 
Example #10
Source File: SqlTests.java    From Quicksql with MIT License 6 votes vote down vote up
private static ColumnMetaData.Rep rep(int columnType) {
  switch (columnType) {
  case Types.BOOLEAN:
    return ColumnMetaData.Rep.BOOLEAN;
  case Types.TINYINT:
    return ColumnMetaData.Rep.BYTE;
  case Types.SMALLINT:
    return ColumnMetaData.Rep.SHORT;
  case Types.INTEGER:
    return ColumnMetaData.Rep.INTEGER;
  case Types.BIGINT:
    return ColumnMetaData.Rep.LONG;
  case Types.REAL:
    return ColumnMetaData.Rep.FLOAT;
  case Types.DOUBLE:
    return ColumnMetaData.Rep.DOUBLE;
  case Types.TIME:
    return ColumnMetaData.Rep.JAVA_SQL_TIME;
  case Types.TIMESTAMP:
    return ColumnMetaData.Rep.JAVA_SQL_TIMESTAMP;
  case Types.DATE:
    return ColumnMetaData.Rep.JAVA_SQL_DATE;
  default:
    return ColumnMetaData.Rep.OBJECT;
  }
}
 
Example #11
Source File: CalcitePrepare.java    From calcite with Apache License 2.0 6 votes vote down vote up
public CalciteSignature(String sql,
    List<AvaticaParameter> parameterList,
    Map<String, Object> internalParameters,
    RelDataType rowType,
    List<ColumnMetaData> columns,
    Meta.CursorFactory cursorFactory,
    CalciteSchema rootSchema,
    List<RelCollation> collationList,
    long maxRowCount,
    Bindable<T> bindable,
    Meta.StatementType statementType) {
  super(columns, sql, parameterList, internalParameters, cursorFactory,
      statementType);
  this.rowType = rowType;
  this.rootSchema = rootSchema;
  this.collationList = collationList;
  this.maxRowCount = maxRowCount;
  this.bindable = bindable;
}
 
Example #12
Source File: KylinMeta.java    From kylin with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
private MetaResultSet createResultSet(List iterable, Class clazz, String... names) {
    final List<ColumnMetaData> columns = new ArrayList<ColumnMetaData>();
    final List<Field> fields = new ArrayList<Field>();
    final List<String> fieldNames = new ArrayList<String>();
    for (String name : names) {
        final int index = fields.size();
        final String fieldName = AvaticaUtils.toCamelCase(name);
        final Field field;
        try {
            field = clazz.getField(fieldName);
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        }
        columns.add(columnMetaData(name, index, field.getType(), true));
        fields.add(field);
        fieldNames.add(fieldName);
    }

    CursorFactory cursorFactory = CursorFactory.record(clazz, fields, fieldNames);
    Signature signature = new Signature(columns, "", null, Collections.<String, Object> emptyMap(), cursorFactory, StatementType.SELECT);
    StatementHandle sh = this.createStatement(connection().handle);
    Frame frame = new Frame(0, true, iterable);

    return MetaResultSet.create(connection().id, sh.id, true, signature, frame);
}
 
Example #13
Source File: ColumnLoader.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Creates a column loader, and performs the load.
 *
 * @param typeFactory Type factory
 * @param sourceTable Source data
 * @param protoRowType Logical row type
 * @param repList Physical row types, or null if not known */
ColumnLoader(JavaTypeFactory typeFactory,
    Enumerable<T> sourceTable,
    RelProtoDataType protoRowType,
    List<ColumnMetaData.Rep> repList) {
  this.typeFactory = typeFactory;
  final RelDataType rowType = protoRowType.apply(typeFactory);
  if (repList == null) {
    repList =
        Collections.nCopies(rowType.getFieldCount(),
            ColumnMetaData.Rep.OBJECT);
  }
  sourceTable.into(list);
  final int[] sorts = {-1};
  load(rowType, repList, sorts);
  this.sortField = sorts[0];
}
 
Example #14
Source File: CalciteMetaImpl.java    From Quicksql with MIT License 6 votes vote down vote up
private <E> MetaResultSet createResultSet(Enumerable<E> enumerable,
    Class clazz, String... names) {
  final List<ColumnMetaData> columns = new ArrayList<>();
  final List<Field> fields = new ArrayList<>();
  final List<String> fieldNames = new ArrayList<>();
  for (String name : names) {
    final int index = fields.size();
    final String fieldName = AvaticaUtils.toCamelCase(name);
    final Field field;
    try {
      field = clazz.getField(fieldName);
    } catch (NoSuchFieldException e) {
      throw new RuntimeException(e);
    }
    columns.add(columnMetaData(name, index, field.getType(), false));
    fields.add(field);
    fieldNames.add(fieldName);
  }
  //noinspection unchecked
  final Iterable<Object> iterable = (Iterable<Object>) (Iterable) enumerable;
  return createResultSet(Collections.emptyMap(),
      columns, CursorFactory.record(clazz, fields, fieldNames),
      new Frame(0, true, iterable));
}
 
Example #15
Source File: KylinClient.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private List<ColumnMetaData> convertColumnMeta(SQLResponseStub queryResp) {
    List<ColumnMetaData> metas = new ArrayList<ColumnMetaData>();
    for (int i = 0; i < queryResp.getColumnMetas().size(); i++) {
        SQLResponseStub.ColumnMetaStub scm = queryResp.getColumnMetas().get(i);
        Class columnClass = convertType(scm.getColumnType());
        ScalarType type = ColumnMetaData.scalar(scm.getColumnType(), scm.getColumnTypeName(), Rep.of(columnClass));

        ColumnMetaData meta = new ColumnMetaData(i, scm.isAutoIncrement(), scm.isCaseSensitive(),
                scm.isSearchable(), scm.isCurrency(), scm.getIsNullable(), scm.isSigned(), scm.getDisplaySize(),
                scm.getLabel(), scm.getName(), scm.getSchemaName(), scm.getPrecision(), scm.getScale(),
                scm.getTableName(), scm.getSchemaName(), type, scm.isReadOnly(), scm.isWritable(), scm.isWritable(),
                columnClass.getCanonicalName());

        metas.add(meta);
    }

    return metas;
}
 
Example #16
Source File: TypedValue.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
private boolean isSerial(ColumnMetaData.Rep rep, Object value) {
  if (value == null) {
    return true;
  }
  switch (rep) {
  case BYTE_STRING:
    return value instanceof String;
  case JAVA_SQL_DATE:
  case JAVA_SQL_TIME:
    return value instanceof Integer;
  case JAVA_SQL_TIMESTAMP:
  case JAVA_UTIL_DATE:
    return value instanceof Long;
  default:
    return true;
  }
}
 
Example #17
Source File: TypedValueTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@Test public void testArrays() {
  List<Object> serialObj = Arrays.<Object>asList(1, 2, 3, 4);
  ArrayImpl.Factory factory = new ArrayFactoryImpl(Unsafe.localCalendar().getTimeZone());
  ScalarType scalarType = ColumnMetaData.scalar(Types.INTEGER, "INTEGER", Rep.INTEGER);
  Array a1 = factory.createArray(scalarType, serialObj);
  TypedValue tv1 = TypedValue.ofJdbc(Rep.ARRAY, a1, Unsafe.localCalendar());
  Object jdbcObj = tv1.toJdbc(Unsafe.localCalendar());
  assertTrue("The JDBC object is an " + jdbcObj.getClass(), jdbcObj instanceof Array);
  Object localObj = tv1.toLocal();
  assertTrue("The local object is an " + localObj.getClass(), localObj instanceof List);
  Common.TypedValue protoTv1 = tv1.toProto();
  assertEquals(serialObj.size(), protoTv1.getArrayValueCount());
  TypedValue tv1Copy = TypedValue.fromProto(protoTv1);
  Object jdbcObjCopy = tv1Copy.toJdbc(Unsafe.localCalendar());
  assertTrue("The JDBC object is an " + jdbcObjCopy.getClass(), jdbcObjCopy instanceof Array);
  Object localObjCopy = tv1Copy.toLocal();
  assertTrue("The local object is an " + localObjCopy.getClass(), localObjCopy instanceof List);
}
 
Example #18
Source File: DruidQuery.java    From calcite with Apache License 2.0 6 votes vote down vote up
private ColumnMetaData.Rep getPrimitive(RelDataTypeField field) {
  switch (field.getType().getSqlTypeName()) {
  case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
  case TIMESTAMP:
    return ColumnMetaData.Rep.JAVA_SQL_TIMESTAMP;
  case BIGINT:
    return ColumnMetaData.Rep.LONG;
  case INTEGER:
    return ColumnMetaData.Rep.INTEGER;
  case SMALLINT:
    return ColumnMetaData.Rep.SHORT;
  case TINYINT:
    return ColumnMetaData.Rep.BYTE;
  case REAL:
    return ColumnMetaData.Rep.FLOAT;
  case DOUBLE:
  case FLOAT:
    return ColumnMetaData.Rep.DOUBLE;
  default:
    return null;
  }
}
 
Example #19
Source File: ArrayTypeTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@Test public void varbinaryArrays() throws Exception {
  try (Connection conn = DriverManager.getConnection(url)) {
    ScalarType component = ColumnMetaData.scalar(Types.VARBINARY, "VARBINARY", Rep.BYTE_STRING);
    // [ Array(binary, binary, binary), Array(binary, binary, binary), ...]
    List<Array> arrays = new ArrayList<>();
    // Construct the data
    for (int i = 0; i < 5; i++) {
      List<byte[]> elements = new ArrayList<>();
      for (int j = 0; j < 5; j++) {
        elements.add((i + "_" + j).getBytes(UTF_8));
      }
      arrays.add(createArray("VARBINARY", component, elements));
    }
    writeAndReadArrays(conn, "binary_arrays", "VARBINARY", component, arrays,
        BYTE_ARRAY_ARRAY_VALIDATOR);
  }
}
 
Example #20
Source File: ArrayTypeTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@Test public void arraysOfByteArrays() throws Exception {
  final Random r = new Random();
  try (Connection conn = DriverManager.getConnection(url)) {
    ScalarType component = ColumnMetaData.scalar(Types.TINYINT, "TINYINT", Rep.BYTE);
    // [ Array([b, b, b]), Array([b, b, b]), ... ]
    List<Array> arrays = new ArrayList<>();
    // Construct the data
    for (int i = 0; i < 5; i++) {
      List<Byte> elements = new ArrayList<>();
      for (int j = 0; j < 5; j++) {
        byte value = (byte) r.nextInt(Byte.MAX_VALUE);
        // 50% of the time, negate the value
        if (0 == r.nextInt(2)) {
          value *= -1;
        }
        elements.add(Byte.valueOf(value));
      }
      arrays.add(createArray("TINYINT", component, elements));
    }
    // Verify read/write
    writeAndReadArrays(conn, "byte_arrays", "TINYINT", component, arrays, BYTE_ARRAY_VALIDATOR);
  }
}
 
Example #21
Source File: ArrayTypeTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@Test public void doubleArrays() throws Exception {
  final Random r = new Random();
  try (Connection conn = DriverManager.getConnection(url)) {
    ScalarType component = ColumnMetaData.scalar(Types.DOUBLE, "DOUBLE", Rep.DOUBLE);
    List<Array> arrays = new ArrayList<>();
    // Construct the data
    for (int i = 0; i < 3; i++) {
      List<Double> elements = new ArrayList<>();
      for (int j = 0; j < 7; j++) {
        double element = r.nextDouble();
        if (r.nextBoolean()) {
          element *= -1;
        }
        elements.add(element);
      }
      arrays.add(createArray("DOUBLE", component, elements));
    }
    writeAndReadArrays(conn, "float_arrays", "DOUBLE", component, arrays,
        PRIMITIVE_LIST_VALIDATOR);
  }
}
 
Example #22
Source File: ArrayTypeTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@Test public void stringArrays() throws Exception {
  try (Connection conn = DriverManager.getConnection(url)) {
    ScalarType component = ColumnMetaData.scalar(Types.VARCHAR, "VARCHAR", Rep.STRING);
    List<Array> arrays = new ArrayList<>();
    // Construct the data
    for (int i = 0; i < 5; i++) {
      List<String> elements = new ArrayList<>();
      for (int j = 0; j < 5; j++) {
        elements.add(i + "_" + j);
      }
      arrays.add(createArray("VARCHAR", component, elements));
    }
    // Verify read/write
    writeAndReadArrays(conn, "string_arrays", "VARCHAR", component, arrays,
        PRIMITIVE_LIST_VALIDATOR);
  }
}
 
Example #23
Source File: DruidQuery.java    From calcite with Apache License 2.0 6 votes vote down vote up
public void run() throws InterruptedException {
  final List<ColumnMetaData.Rep> fieldTypes = new ArrayList<>();
  for (RelDataTypeField field : query.getRowType().getFieldList()) {
    fieldTypes.add(getPrimitive(field));
  }
  final DruidConnectionImpl connection =
      new DruidConnectionImpl(query.druidTable.schema.url,
          query.druidTable.schema.coordinatorUrl);
  final boolean limitQuery = containsLimit(querySpec);
  final DruidConnectionImpl.Page page = new DruidConnectionImpl.Page();
  do {
    final String queryString =
        querySpec.getQueryString(page.pagingIdentifier, page.offset);
    connection.request(querySpec.queryType, queryString, sink,
        querySpec.fieldNames, fieldTypes, page);
  } while (!limitQuery
      && page.pagingIdentifier != null
      && page.totalRowCount > 0);
}
 
Example #24
Source File: CalciteMetaImpl.java    From calcite with Apache License 2.0 6 votes vote down vote up
protected MetaResultSet createResultSet(
    Map<String, Object> internalParameters, List<ColumnMetaData> columns,
    CursorFactory cursorFactory, final Frame firstFrame) {
  try {
    final CalciteConnectionImpl connection = getConnection();
    final AvaticaStatement statement = connection.createStatement();
    final CalcitePrepare.CalciteSignature<Object> signature =
        new CalcitePrepare.CalciteSignature<Object>("",
            ImmutableList.of(), internalParameters, null,
            columns, cursorFactory, null, ImmutableList.of(), -1,
            null, Meta.StatementType.SELECT) {
          @Override public Enumerable<Object> enumerable(
              DataContext dataContext) {
            return Linq4j.asEnumerable(firstFrame.rows);
          }
        };
    return MetaResultSet.create(connection.id, statement.getId(), true,
        signature, firstFrame);
  } catch (SQLException e) {
    throw new RuntimeException(e);
  }
}
 
Example #25
Source File: DummyClient.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public QueryResult executeQuery(String sql, List<Object> paramValues, Map<String, String> queryToggles) throws IOException {
    List<Object> data = new ArrayList<Object>();

    ZoneId utc = ZoneId.of("UTC");
    LocalDate localDate = Date.valueOf("2019-04-27").toLocalDate();
    LocalDateTime localDateTime = Timestamp.valueOf("2019-04-27 17:30:03").toLocalDateTime();
    Date date = new Date(localDate.atStartOfDay(utc).toInstant().toEpochMilli());
    Timestamp timestamp = new Timestamp(localDateTime.atZone(utc).toInstant().toEpochMilli());

    Object[] row = new Object[] { "foo", "bar", "tool", date, timestamp };
    data.add(row);

    List<ColumnMetaData> meta = new ArrayList<ColumnMetaData>();
    meta.add(ColumnMetaData.dummy(ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
    meta.add(ColumnMetaData.dummy(ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
    meta.add(ColumnMetaData.dummy(ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
    meta.add(ColumnMetaData.dummy(ColumnMetaData.scalar(Types.DATE, "date", Rep.JAVA_SQL_DATE), true));
    meta.add(ColumnMetaData.dummy(ColumnMetaData.scalar(Types.TIMESTAMP, "timestamp", Rep.JAVA_SQL_TIMESTAMP),
            true));

    return new QueryResult(meta, data);
}
 
Example #26
Source File: KylinMeta.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
private MetaResultSet createResultSet(List iterable, Class clazz, String... names) {
    final List<ColumnMetaData> columns = new ArrayList<ColumnMetaData>();
    final List<Field> fields = new ArrayList<Field>();
    final List<String> fieldNames = new ArrayList<String>();
    for (String name : names) {
        final int index = fields.size();
        final String fieldName = AvaticaUtils.toCamelCase(name);
        final Field field;
        try {
            field = clazz.getField(fieldName);
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        }
        columns.add(columnMetaData(name, index, field.getType(), true));
        fields.add(field);
        fieldNames.add(fieldName);
    }

    CursorFactory cursorFactory = CursorFactory.record(clazz, fields, fieldNames);
    Signature signature = new Signature(columns, "", null, Collections.<String, Object> emptyMap(), cursorFactory, StatementType.SELECT);
    StatementHandle sh = this.createStatement(connection().handle);
    Frame frame = new Frame(0, true, iterable);

    return MetaResultSet.create(connection().id, sh.id, true, signature, frame);
}
 
Example #27
Source File: DremioColumnMetaDataList.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Gets AvaticaType carrying both JDBC {@code java.sql.Type.*} type code
 * and SQL type name for given RPC-level type (from batch schema).
 */
private static AvaticaType getAvaticaType( MajorType rpcDateType ) {
  final String sqlTypeName = Types.getSqlTypeName( rpcDateType );
  final int jdbcTypeId = Types.getJdbcTypeCode( sqlTypeName );
  return ColumnMetaData.scalar( jdbcTypeId, sqlTypeName,
      Rep.BOOLEAN /* dummy value, unused */ );
}
 
Example #28
Source File: KylinConnection.java    From kylin with Apache License 2.0 5 votes vote down vote up
Signature mockPreparedSignature(String sql) {
    List<AvaticaParameter> params = new ArrayList<AvaticaParameter>();
    int startIndex = 0;
    while (sql.indexOf("?", startIndex) >= 0) {
        AvaticaParameter param = new AvaticaParameter(false, 0, 0, 0, null, null, null);
        params.add(param);
        startIndex = sql.indexOf("?", startIndex) + 1;
    }

    ArrayList<ColumnMetaData> columns = new ArrayList<ColumnMetaData>();
    Map<String, Object> internalParams = Collections.<String, Object> emptyMap();

    return new Meta.Signature(columns, sql, params, internalParams, CursorFactory.ARRAY, Meta.StatementType.SELECT);
}
 
Example #29
Source File: CalcitePrepareImpl.java    From calcite with Apache License 2.0 5 votes vote down vote up
private ColumnMetaData.AvaticaType avaticaType(JavaTypeFactory typeFactory,
    RelDataType type, RelDataType fieldType) {
  final String typeName = getTypeName(type);
  if (type.getComponentType() != null) {
    final ColumnMetaData.AvaticaType componentType =
        avaticaType(typeFactory, type.getComponentType(), null);
    final Type clazz = typeFactory.getJavaClass(type.getComponentType());
    final ColumnMetaData.Rep rep = ColumnMetaData.Rep.of(clazz);
    assert rep != null;
    return ColumnMetaData.array(componentType, typeName, rep);
  } else {
    int typeOrdinal = getTypeOrdinal(type);
    switch (typeOrdinal) {
    case Types.STRUCT:
      final List<ColumnMetaData> columns = new ArrayList<>(type.getFieldList().size());
      for (RelDataTypeField field : type.getFieldList()) {
        columns.add(
            metaData(typeFactory, field.getIndex(), field.getName(),
                field.getType(), null, null));
      }
      return ColumnMetaData.struct(columns);
    case ExtraSqlTypes.GEOMETRY:
      typeOrdinal = Types.VARCHAR;
      // fall through
    default:
      final Type clazz =
          typeFactory.getJavaClass(Util.first(fieldType, type));
      final ColumnMetaData.Rep rep = ColumnMetaData.Rep.of(clazz);
      assert rep != null;
      return ColumnMetaData.scalar(typeOrdinal, typeName, rep);
    }
  }
}
 
Example #30
Source File: CalcitePrepareImpl.java    From Quicksql with MIT License 5 votes vote down vote up
private ColumnMetaData metaData(JavaTypeFactory typeFactory, int ordinal,
    String fieldName, RelDataType type, RelDataType fieldType,
    List<String> origins) {
  final ColumnMetaData.AvaticaType avaticaType =
      avaticaType(typeFactory, type, fieldType);
  return new ColumnMetaData(
      ordinal,
      false,
      true,
      false,
      false,
      type.isNullable()
          ? DatabaseMetaData.columnNullable
          : DatabaseMetaData.columnNoNulls,
      true,
      type.getPrecision(),
      fieldName,
      origin(origins, 0),
      origin(origins, 2),
      getPrecision(type),
      getScale(type),
      origin(origins, 1),
      null,
      avaticaType,
      true,
      false,
      false,
      avaticaType.columnClassName());
}