当前位置: 首页>>代码示例>>Java>>正文


Java Rep类代码示例

本文整理汇总了Java中org.apache.calcite.avatica.ColumnMetaData.Rep的典型用法代码示例。如果您正苦于以下问题:Java Rep类的具体用法?Java Rep怎么用?Java Rep使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Rep类属于org.apache.calcite.avatica.ColumnMetaData包,在下文中一共展示了Rep类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shortArrays

import org.apache.calcite.avatica.ColumnMetaData.Rep; //导入依赖的package包/类
@Test public void shortArrays() throws Exception {
  final Random r = new Random();
  try (Connection conn = DriverManager.getConnection(url)) {
    ScalarType component = ColumnMetaData.scalar(Types.SMALLINT, "SMALLINT", Rep.SHORT);
    List<Array> arrays = new ArrayList<>();
    // Construct the data
    for (int i = 0; i < 5; i++) {
      List<Short> elements = new ArrayList<>();
      for (int j = 0; j < 5; j++) {
        short value = (short) r.nextInt(Short.MAX_VALUE);
        // 50% of the time, negate the value
        if (0 == r.nextInt(2)) {
          value *= -1;
        }
        elements.add(Short.valueOf(value));
      }
      arrays.add(createArray("SMALLINT", component, elements));
    }
    // Verify read/write
    writeAndReadArrays(conn, "short_arrays", "SMALLINT", component, arrays,
        PRIMITIVE_LIST_VALIDATOR);
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:24,代码来源:ArrayTypeTest.java

示例2: shortArraysWithNull

import org.apache.calcite.avatica.ColumnMetaData.Rep; //导入依赖的package包/类
@Test public void shortArraysWithNull() throws Exception {
  final Random r = new Random();
  try (Connection conn = DriverManager.getConnection(url)) {
    ScalarType component = ColumnMetaData.scalar(Types.SMALLINT, "SMALLINT", Rep.SHORT);
    List<Array> arrays = new ArrayList<>();
    // Construct the data
    for (int i = 0; i < 5; i++) {
      List<Short> elements = new ArrayList<>();
      for (int j = 0; j < 4; j++) {
        short value = (short) r.nextInt(Short.MAX_VALUE);
        // 50% of the time, negate the value
        if (0 == r.nextInt(2)) {
          value *= -1;
        }
        elements.add(Short.valueOf(value));
      }
      elements.add(null);
      arrays.add(createArray("SMALLINT", component, elements));
    }
    // Verify read/write
    writeAndReadArrays(conn, "short_arrays", "SMALLINT", component, arrays,
        PRIMITIVE_LIST_VALIDATOR);
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:25,代码来源:ArrayTypeTest.java

示例3: longArrays

import org.apache.calcite.avatica.ColumnMetaData.Rep; //导入依赖的package包/类
@Test public void longArrays() throws Exception {
  final Random r = new Random();
  try (Connection conn = DriverManager.getConnection(url)) {
    ScalarType component = ColumnMetaData.scalar(Types.BIGINT, "BIGINT", Rep.LONG);
    List<Array> arrays = new ArrayList<>();
    // Construct the data
    for (int i = 0; i < 5; i++) {
      List<Long> elements = new ArrayList<>();
      for (int j = 0; j < 5; j++) {
        elements.add(r.nextLong());
      }
      arrays.add(createArray("BIGINT", component, elements));
    }
    // Verify read/write
    writeAndReadArrays(conn, "long_arrays", "BIGINT", component, arrays,
        PRIMITIVE_LIST_VALIDATOR);
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:19,代码来源:ArrayTypeTest.java

示例4: stringArrays

import org.apache.calcite.avatica.ColumnMetaData.Rep; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:18,代码来源:ArrayTypeTest.java

示例5: bigintArrays

import org.apache.calcite.avatica.ColumnMetaData.Rep; //导入依赖的package包/类
@Test public void bigintArrays() throws Exception {
  final Random r = new Random();
  try (Connection conn = DriverManager.getConnection(url)) {
    ScalarType component = ColumnMetaData.scalar(Types.BIGINT, "BIGINT", Rep.LONG);
    List<Array> arrays = new ArrayList<>();
    // Construct the data
    for (int i = 0; i < 3; i++) {
      List<Long> elements = new ArrayList<>();
      for (int j = 0; j < 7; j++) {
        long element = r.nextLong();
        if (r.nextBoolean()) {
          element *= -1;
        }
        elements.add(element);
      }
      arrays.add(createArray("BIGINT", component, elements));
    }
    writeAndReadArrays(conn, "long_arrays", "BIGINT", component, arrays,
        PRIMITIVE_LIST_VALIDATOR);
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:22,代码来源:ArrayTypeTest.java

示例6: doubleArrays

import org.apache.calcite.avatica.ColumnMetaData.Rep; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:22,代码来源:ArrayTypeTest.java

示例7: arraysOfByteArrays

import org.apache.calcite.avatica.ColumnMetaData.Rep; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:24,代码来源:ArrayTypeTest.java

示例8: varbinaryArrays

import org.apache.calcite.avatica.ColumnMetaData.Rep; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:18,代码来源:ArrayTypeTest.java

示例9: createArray

import org.apache.calcite.avatica.ColumnMetaData.Rep; //导入依赖的package包/类
/**
 * Creates a JDBC {@link Array} from a list of values.
 *
 * @param typeName the SQL type name of the elements in the array
 * @param componentType The Avatica type for the array elements
 * @param arrayValues The array elements
 * @return An Array instance for the given component and values
 */
@SuppressWarnings("unchecked")
private <T> Array createArray(String typeName, AvaticaType componentType, List<T> arrayValues) {
  // Make a "row" with one "column" (which is really a list)
  final List<Object> oneRow = Collections.singletonList((Object) arrayValues);
  // Make an iterator over this one "row"
  final Iterator<List<Object>> rowIterator = Collections.singletonList(oneRow).iterator();

  ArrayType array = ColumnMetaData.array(componentType, typeName, Rep.ARRAY);
  try (ListIteratorCursor cursor = new ListIteratorCursor(rowIterator)) {
    List<ColumnMetaData> types = Collections.singletonList(ColumnMetaData.dummy(array, true));
    Calendar calendar = Unsafe.localCalendar();
    List<Accessor> accessors = cursor.createAccessors(types, calendar, null);
    assertTrue("Expected at least one accessor, found " + accessors.size(),
        !accessors.isEmpty());
    ArrayAccessor arrayAccessor = (ArrayAccessor) accessors.get(0);

    return new ArrayImpl((List<Object>) arrayValues, arrayAccessor);
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:28,代码来源:ArrayTypeTest.java

示例10: createArrayOf

import org.apache.calcite.avatica.ColumnMetaData.Rep; //导入依赖的package包/类
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
  @SuppressWarnings("unchecked")
  List<Object> elementList = (List<Object>) AvaticaUtils.primitiveList(elements);
  SqlType type;
  try {
    type = SqlType.valueOf(typeName);
  } catch (IllegalArgumentException e) {
    throw new SQLException("Could not find JDBC type for '" + typeName + "'");
  }
  AvaticaType avaticaType = null;
  switch (type) {
  case ARRAY:
    // TODO: Nested ARRAYs
    throw helper.createException("Cannot create an ARRAY of ARRAY's");
  case STRUCT:
    // TODO: ARRAYs of STRUCTs
    throw helper.createException("Cannot create an ARRAY of STRUCT's");
  default:
    // This is an ARRAY, we need to use Objects, not primitives (nullable).
    avaticaType = ColumnMetaData.scalar(type.id, typeName, Rep.nonPrimitiveRepOf(type));
  }
  ArrayFactoryImpl arrayFactory = new ArrayFactoryImpl(getTimeZone());
  return arrayFactory.createArray(avaticaType, elementList);
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:25,代码来源:AvaticaConnection.java

示例11: create

import org.apache.calcite.avatica.ColumnMetaData.Rep; //导入依赖的package包/类
@Override public ResultSet create(AvaticaType elementType, Iterable<Object> elements) {
  // The ColumnMetaData for offset "1" in the ResultSet for an Array.
  ScalarType arrayOffsetType = ColumnMetaData.scalar(Types.INTEGER, "INTEGER", Rep.PRIMITIVE_INT);
  // Two columns (types) in the ResultSet we will create
  List<ColumnMetaData> types = Arrays.asList(ColumnMetaData.dummy(arrayOffsetType, false),
      ColumnMetaData.dummy(elementType, true));
  List<List<Object>> rows = createResultSetRowsForArrayData(elements);
  // `(List<Object>) rows` is a compile error.
  @SuppressWarnings({ "unchecked", "rawtypes" })
  List<Object> untypedRows = (List<Object>) ((List) rows);
  try (ListIteratorCursor cursor = new ListIteratorCursor(rows.iterator())) {
    final String sql = "MOCKED";
    QueryState state = new QueryState(sql);
    Meta.Signature signature = new Meta.Signature(types, sql,
        Collections.<AvaticaParameter>emptyList(), Collections.<String, Object>emptyMap(),
        Meta.CursorFactory.LIST, Meta.StatementType.SELECT);
    AvaticaResultSetMetaData resultSetMetaData = new AvaticaResultSetMetaData(null, sql,
        signature);
    Meta.Frame frame = new Meta.Frame(0, true, untypedRows);
    AvaticaResultSet resultSet = new AvaticaResultSet(null, state, signature, resultSetMetaData,
        timeZone, frame);
    resultSet.execute2(cursor, types);
    return resultSet;
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:26,代码来源:ArrayFactoryImpl.java

示例12: isSerial

import org.apache.calcite.avatica.ColumnMetaData.Rep; //导入依赖的package包/类
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;
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:18,代码来源:TypedValue.java

示例13: serializeArray

import org.apache.calcite.avatica.ColumnMetaData.Rep; //导入依赖的package包/类
Common.TypedValue serializeArray(List<Object> list, Common.TypedValue.Builder builder,
    Common.Rep protoArrayComponentRep) {
  for (Object element : list) {
    if (element instanceof List) {
      // We have a list of lists: recursively build up the protobuf
      @SuppressWarnings("unchecked")
      List<Object> subList = (List<Object>) element;
      Common.TypedValue.Builder subListBuilder = Common.TypedValue.newBuilder();
      // This is "technically" an array, but we just persist the underlying component type
      subListBuilder.setType(protoArrayComponentRep);
      Common.TypedValue protoSubList = serializeArray(subList, subListBuilder,
          protoArrayComponentRep);
      builder.addArrayValue(protoSubList);
    } else {
      // We have a list of "scalars", just serialize the value
      Common.TypedValue.Builder elementBuilder = Common.TypedValue.newBuilder();
      if (null == element) {
        writeToProtoWithType(elementBuilder, null, Common.Rep.NULL);
      } else {
        writeToProtoWithType(elementBuilder, element, protoArrayComponentRep);
      }
      builder.addArrayValue(elementBuilder.build());
    }
  }
  return builder.build();
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:27,代码来源:TypedValue.java

示例14: testArrayWithOffsets

import org.apache.calcite.avatica.ColumnMetaData.Rep; //导入依赖的package包/类
@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]);
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:25,代码来源:ArrayImplTest.java

示例15: testBase64

import org.apache.calcite.avatica.ColumnMetaData.Rep; //导入依赖的package包/类
@Test public void testBase64() {
  byte[] bytes = "qwertyasdf".getBytes(UTF_8);
  // Plain bytes get put into protobuf for simplicitly
  Common.TypedValue proto = Common.TypedValue.newBuilder().setBytesValue(
      com.google.protobuf.ByteString.copyFrom(bytes))
      .setType(Common.Rep.BYTE_STRING).build();

  // But we should get back a b64-string to make sure TypedValue doesn't get confused.
  Object deserializedObj = TypedValue.getSerialFromProto(proto);
  assertThat(deserializedObj, is(instanceOf(String.class)));
  assertEquals(new ByteString(bytes).toBase64String(), (String) deserializedObj);

  // But we should get a non-b64 byte array as the JDBC representation
  deserializedObj =
      TypedValue.protoToJdbc(proto, DateTimeUtils.calendar());
  assertThat(deserializedObj, is(instanceOf(byte[].class)));
  assertArrayEquals(bytes, (byte[]) deserializedObj);
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:19,代码来源:TypedValueTest.java


注:本文中的org.apache.calcite.avatica.ColumnMetaData.Rep类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。