本文整理汇总了Java中org.apache.calcite.avatica.ColumnMetaData.Rep类的典型用法代码示例。如果您正苦于以下问题:Java Rep类的具体用法?Java Rep怎么用?Java Rep使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Rep类属于org.apache.calcite.avatica.ColumnMetaData包,在下文中一共展示了Rep类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: testProtobufBytesNotSentAsBase64
import org.apache.calcite.avatica.ColumnMetaData.Rep; //导入依赖的package包/类
@Test public void testProtobufBytesNotSentAsBase64() {
final byte[] bytes = "asdf".getBytes(UTF_8);
final byte[] b64Bytes = Base64.encodeBytes(bytes).getBytes(UTF_8);
TypedValue tv = TypedValue.ofLocal(Rep.BYTE_STRING, new ByteString(bytes));
// JSON encodes it as base64
assertEquals(new String(b64Bytes, UTF_8), tv.value);
// Get the protobuf variant
Common.TypedValue protoTv = tv.toProto();
Common.Rep protoRep = protoTv.getType();
assertEquals(Common.Rep.BYTE_STRING, protoRep);
// The pb variant should have the native bytes of the original value
com.google.protobuf.ByteString protoByteString = protoTv.getBytesValue();
assertNotNull(protoByteString);
assertArrayEquals(bytes, protoByteString.toByteArray());
// We should have the b64 string as a backwards compatibility feature
assertEquals(new String(b64Bytes, UTF_8),
protoTv.getStringValue());
}
开发者ID:apache,项目名称:calcite-avatica,代码行数:22,代码来源:TypedValueTest.java
示例17: testLegacyBase64StringEncodingForBytes
import org.apache.calcite.avatica.ColumnMetaData.Rep; //导入依赖的package包/类
@Test public void testLegacyBase64StringEncodingForBytes() {
// CALCITE-1103 CALCITE-1209 We observed that binary data was being
// serialized as base-64 encoded strings instead of the native binary
// data type in protobufs. We need to still handle older clients sending
// data in this form.
final byte[] bytes = "asdf".getBytes(UTF_8);
final String base64Str = Base64.encodeBytes(bytes);
Common.TypedValue.Builder builder = Common.TypedValue.newBuilder();
builder.setStringValue(base64Str);
builder.setType(Common.Rep.BYTE_STRING);
Common.TypedValue protoTv = builder.build();
TypedValue tv = TypedValue.fromProto(protoTv);
assertEquals(Rep.BYTE_STRING, tv.type);
assertEquals(base64Str, tv.value);
}
开发者ID:apache,项目名称:calcite-avatica,代码行数:17,代码来源:TypedValueTest.java
示例18: testArrays
import org.apache.calcite.avatica.ColumnMetaData.Rep; //导入依赖的package包/类
@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);
}
开发者ID:apache,项目名称:calcite-avatica,代码行数:19,代码来源:TypedValueTest.java
示例19: convertColumnMeta
import org.apache.calcite.avatica.ColumnMetaData.Rep; //导入依赖的package包/类
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;
}
开发者ID:apache,项目名称:kylin,代码行数:19,代码来源:KylinClient.java
示例20: simpleArrayTest
import org.apache.calcite.avatica.ColumnMetaData.Rep; //导入依赖的package包/类
@Test public void simpleArrayTest() throws Exception {
try (Connection conn = DriverManager.getConnection(url)) {
ScalarType varcharComponent = ColumnMetaData.scalar(Types.VARCHAR, "VARCHAR", Rep.STRING);
List<Array> varcharArrays = new ArrayList<>();
for (int i = 0; i < 5; i++) {
List<String> value = Collections.singletonList(Integer.toString(i));
varcharArrays.add(createArray("VARCHAR", varcharComponent, value));
}
writeAndReadArrays(conn, "varchar_arrays", "VARCHAR(30)",
varcharComponent, varcharArrays, PRIMITIVE_LIST_VALIDATOR);
}
}
开发者ID:apache,项目名称:calcite-avatica,代码行数:13,代码来源:ArrayTypeTest.java
注:本文中的org.apache.calcite.avatica.ColumnMetaData.Rep类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论