use of org.apache.calcite.avatica.ColumnMetaData.ScalarType in project calcite-avatica by apache.
the class ArrayTypeTest method shortArraysWithNull.
@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);
}
}
use of org.apache.calcite.avatica.ColumnMetaData.ScalarType in project calcite-avatica by apache.
the class ArrayTypeTest method doubleArrays.
@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);
}
}
use of org.apache.calcite.avatica.ColumnMetaData.ScalarType in project calcite-avatica by apache.
the class ArrayTypeTest method booleanArrays.
@Test
public void booleanArrays() throws Exception {
final Random r = new Random();
try (Connection conn = DriverManager.getConnection(url)) {
ScalarType component = ColumnMetaData.scalar(Types.BOOLEAN, "BOOLEAN", Rep.BOOLEAN);
List<Array> arrays = new ArrayList<>();
// Construct the data
for (int i = 0; i < 5; i++) {
List<Boolean> elements = new ArrayList<>();
for (int j = 0; j < 5; j++) {
switch(r.nextInt(3)) {
case 0:
elements.add(Boolean.FALSE);
break;
case 1:
elements.add(Boolean.TRUE);
break;
case 2:
elements.add(null);
break;
default:
fail();
}
}
arrays.add(createArray("BOOLEAN", component, elements));
}
// Verify we can read and write the data
writeAndReadArrays(conn, "boolean_arrays", "BOOLEAN", component, arrays, PRIMITIVE_LIST_VALIDATOR);
}
}
Aggregations