Search in sources :

Example 1 with JsonStringArrayList

use of org.apache.arrow.vector.util.JsonStringArrayList in project java-bigquery by googleapis.

the class ITNightlyBigQueryTest method testIterateAndOrder.

/*
  This tests for the order of the records as well as the value of the records using testForAllDataTypeValues
   */
@Test
public void testIterateAndOrder() throws SQLException {
    Connection connection = getConnection();
    BigQueryResult bigQueryResult = connection.executeSelect(QUERY);
    logger.log(Level.INFO, "Query used: {0}", QUERY);
    ResultSet rs = bigQueryResult.getResultSet();
    int cnt = 0;
    int prevIntegerFieldVal = 0;
    while (rs.next()) {
        if (cnt == 0) {
            // first row is supposed to be null
            assertNull(rs.getString("StringField"));
            assertNull(rs.getString("GeographyField"));
            Object intAryField = rs.getObject("IntegerArrayField");
            if (intAryField instanceof JsonStringArrayList) {
                assertEquals(new JsonStringArrayList(), // null array is returned as an empty array
                ((JsonStringArrayList) intAryField));
            }
            assertFalse(rs.getBoolean("BooleanField"));
            assertTrue(0.0d == rs.getDouble("BigNumericField"));
            assertTrue(0 == rs.getInt("IntegerField"));
            assertTrue(0L == rs.getLong("NumericField"));
            assertNull(rs.getBytes("BytesField"));
            assertNull(rs.getTimestamp("TimestampField"));
            assertNull(rs.getTime("TimeField"));
            assertNull(rs.getDate("DateField"));
            assertNull(rs.getString("JSONField"));
            assertFalse(rs.getBoolean("BooleanField_1"));
            assertNull(rs.getString("StringField_1"));
            // equivalent of testJsonType
            assertNull(rs.getString("hello"));
            assertEquals(0, rs.getInt("id"));
        } else {
            // remaining rows are supposed to be non null
            assertNotNull(rs.getString("StringField"));
            assertNotNull(rs.getString("GeographyField"));
            assertNotNull(rs.getObject("IntegerArrayField"));
            assertTrue(rs.getBoolean("BooleanField"));
            assertTrue(0.0d < rs.getDouble("BigNumericField"));
            assertTrue(0 < rs.getInt("IntegerField"));
            assertTrue(0L < rs.getLong("NumericField"));
            assertNotNull(rs.getBytes("BytesField"));
            assertNotNull(rs.getTimestamp("TimestampField"));
            assertNotNull(rs.getTime("TimeField"));
            assertNotNull(rs.getDate("DateField"));
            assertNotNull(rs.getString("JSONField"));
            assertFalse(rs.getBoolean("BooleanField_1"));
            assertNotNull(rs.getString("StringField_1"));
            // check the order of the records
            assertTrue(prevIntegerFieldVal < rs.getInt("IntegerField"));
            prevIntegerFieldVal = rs.getInt("IntegerField");
            // asserts the value of each row
            testForAllDataTypeValues(rs, cnt);
        }
        ++cnt;
    }
    // all the records were retrieved
    assertEquals(LIMIT_RECS, cnt);
    connection.close();
}
Also used : Connection(com.google.cloud.bigquery.Connection) ResultSet(java.sql.ResultSet) BigQueryResult(com.google.cloud.bigquery.BigQueryResult) JsonStringArrayList(org.apache.arrow.vector.util.JsonStringArrayList) Test(org.junit.Test)

Example 2 with JsonStringArrayList

use of org.apache.arrow.vector.util.JsonStringArrayList in project java-bigquery by googleapis.

the class ITNightlyBigQueryTest method testMultipleRuns.

@Test
public void testMultipleRuns() throws SQLException {
    Connection connection = getConnection();
    BigQueryResult bigQueryResult = connection.executeSelect(MULTI_QUERY);
    logger.log(Level.INFO, "Query used: {0}", MULTI_QUERY);
    ResultSet rs = bigQueryResult.getResultSet();
    int cnt = 0;
    int totalCnt = 0;
    int prevIntegerFieldVal = 0;
    while (rs.next()) {
        if (cnt == 0) {
            // first row is supposed to be null
            assertNull(rs.getString("StringField"));
            assertNull(rs.getString("GeographyField"));
            Object intAryField = rs.getObject("IntegerArrayField");
            if (intAryField instanceof JsonStringArrayList) {
                assertEquals(new JsonStringArrayList(), // null array is returned as an empty array
                ((JsonStringArrayList) intAryField));
            }
            assertFalse(rs.getBoolean("BooleanField"));
            assertTrue(0.0d == rs.getDouble("BigNumericField"));
            assertTrue(0 == rs.getInt("IntegerField"));
            assertTrue(0L == rs.getLong("NumericField"));
            assertNull(rs.getBytes("BytesField"));
            assertNull(rs.getTimestamp("TimestampField"));
            assertNull(rs.getTime("TimeField"));
            assertNull(rs.getDate("DateField"));
            assertNull(rs.getString("JSONField"));
            assertFalse(rs.getBoolean("BooleanField_1"));
            assertNull(rs.getString("StringField_1"));
            // equivalent of testJsonType
            assertNull(rs.getString("hello"));
            assertEquals(0, rs.getInt("id"));
        } else {
            // remaining rows are supposed to be non null
            // check the order of the records
            assertTrue(prevIntegerFieldVal < rs.getInt("IntegerField"));
            prevIntegerFieldVal = rs.getInt("IntegerField");
            // asserts the value of each row
            testForAllDataTypeValues(rs, cnt);
        }
        ++cnt;
    }
    connection.close();
    totalCnt += cnt;
    // Repeat the same run
    connection = getConnection();
    bigQueryResult = connection.executeSelect(MULTI_QUERY);
    rs = bigQueryResult.getResultSet();
    cnt = 0;
    prevIntegerFieldVal = 0;
    while (rs.next()) {
        if (cnt == 0) {
            // first row is supposed to be null
            assertNull(rs.getString("StringField"));
            assertNull(rs.getString("GeographyField"));
            Object intAryField = rs.getObject("IntegerArrayField");
            if (intAryField instanceof JsonStringArrayList) {
                assertEquals(new JsonStringArrayList(), // null array is returned as an empty array
                ((JsonStringArrayList) intAryField));
            }
            assertFalse(rs.getBoolean("BooleanField"));
            assertTrue(0.0d == rs.getDouble("BigNumericField"));
            assertTrue(0 == rs.getInt("IntegerField"));
            assertTrue(0L == rs.getLong("NumericField"));
            assertNull(rs.getBytes("BytesField"));
            assertNull(rs.getTimestamp("TimestampField"));
            assertNull(rs.getTime("TimeField"));
            assertNull(rs.getDate("DateField"));
            assertNull(rs.getString("JSONField"));
            assertFalse(rs.getBoolean("BooleanField_1"));
            assertNull(rs.getString("StringField_1"));
            // equivalent of testJsonType
            assertNull(rs.getString("hello"));
            assertEquals(0, rs.getInt("id"));
        } else {
            // remaining rows are supposed to be non null
            // check the order of the records
            assertTrue(prevIntegerFieldVal < rs.getInt("IntegerField"));
            prevIntegerFieldVal = rs.getInt("IntegerField");
            // asserts the value of each row
            testForAllDataTypeValues(rs, cnt);
        }
        ++cnt;
    }
    connection.close();
    totalCnt += cnt;
    assertEquals(MULTI_LIMIT_RECS * 2, totalCnt);
}
Also used : Connection(com.google.cloud.bigquery.Connection) ResultSet(java.sql.ResultSet) BigQueryResult(com.google.cloud.bigquery.BigQueryResult) JsonStringArrayList(org.apache.arrow.vector.util.JsonStringArrayList) Test(org.junit.Test)

Example 3 with JsonStringArrayList

use of org.apache.arrow.vector.util.JsonStringArrayList in project java-bigquery by googleapis.

the class ITNightlyBigQueryTest method testIterateAndOrderDefaultConnSettings.

/*
  This tests for the order of the records using default connection settings as well as the value of the records using testForAllDataTypeValues
   */
@Test
public void testIterateAndOrderDefaultConnSettings() throws SQLException {
    Connection connection = bigquery.createConnection();
    BigQueryResult bigQueryResult = connection.executeSelect(QUERY);
    logger.log(Level.INFO, "Query used: {0}", QUERY);
    ResultSet rs = bigQueryResult.getResultSet();
    int cnt = 0;
    int prevIntegerFieldVal = 0;
    while (rs.next()) {
        if (cnt == 0) {
            // first row is supposed to be null
            assertNull(rs.getString("StringField"));
            assertNull(rs.getString("GeographyField"));
            Object intAryField = rs.getObject("IntegerArrayField");
            if (intAryField instanceof JsonStringArrayList) {
                assertEquals(new JsonStringArrayList(), // null array is returned as an empty array
                ((JsonStringArrayList) intAryField));
            }
            assertFalse(rs.getBoolean("BooleanField"));
            assertTrue(0.0d == rs.getDouble("BigNumericField"));
            assertTrue(0 == rs.getInt("IntegerField"));
            assertTrue(0L == rs.getLong("NumericField"));
            assertNull(rs.getBytes("BytesField"));
            assertNull(rs.getTimestamp("TimestampField"));
            assertNull(rs.getTime("TimeField"));
            assertNull(rs.getDate("DateField"));
            assertNull(rs.getString("JSONField"));
            assertFalse(rs.getBoolean("BooleanField_1"));
            assertNull(rs.getString("StringField_1"));
            // equivalent of testJsonType
            assertNull(rs.getString("hello"));
            assertEquals(0, rs.getInt("id"));
        } else {
            // remaining rows are supposed to be non null
            assertNotNull(rs.getString("StringField"));
            assertNotNull(rs.getString("GeographyField"));
            assertNotNull(rs.getObject("IntegerArrayField"));
            assertTrue(rs.getBoolean("BooleanField"));
            assertTrue(0.0d < rs.getDouble("BigNumericField"));
            assertTrue(0 < rs.getInt("IntegerField"));
            assertTrue(0L < rs.getLong("NumericField"));
            assertNotNull(rs.getBytes("BytesField"));
            assertNotNull(rs.getTimestamp("TimestampField"));
            assertNotNull(rs.getTime("TimeField"));
            assertNotNull(rs.getDate("DateField"));
            assertNotNull(rs.getString("JSONField"));
            assertFalse(rs.getBoolean("BooleanField_1"));
            assertNotNull(rs.getString("StringField_1"));
            // check the order of the records
            assertTrue(prevIntegerFieldVal < rs.getInt("IntegerField"));
            prevIntegerFieldVal = rs.getInt("IntegerField");
            // asserts the value of each row
            testForAllDataTypeValues(rs, cnt);
        }
        ++cnt;
    }
    // all the records were retrieved
    assertEquals(LIMIT_RECS, cnt);
    assertTrue(connection.close());
}
Also used : Connection(com.google.cloud.bigquery.Connection) ResultSet(java.sql.ResultSet) BigQueryResult(com.google.cloud.bigquery.BigQueryResult) JsonStringArrayList(org.apache.arrow.vector.util.JsonStringArrayList) Test(org.junit.Test)

Example 4 with JsonStringArrayList

use of org.apache.arrow.vector.util.JsonStringArrayList in project conquery by bakdata.

the class ArrowResultGenerationTest method getPrintValue.

private static String getPrintValue(Object obj, ResultType type, PrintSettings settings) {
    if (obj == null) {
        return "null";
    }
    if (type.equals(ResultType.DateRangeT.INSTANCE)) {
        // Special case for daterange in this test because it uses a StructVector, we rebuild the structural information
        List<?> dr = (List<?>) obj;
        StringBuilder sb = new StringBuilder();
        sb.append("{");
        final int min = (int) dr.get(0);
        final int max = (int) dr.get(1);
        // Handle cases where one of the limits is infinity
        if (!CDate.isNegativeInfinity(min)) {
            sb.append("\"min\":").append(min);
        }
        if (!CDate.isNegativeInfinity(min) && !CDate.isPositiveInfinity(max)) {
            sb.append(",");
        }
        if (!CDate.isPositiveInfinity(max)) {
            sb.append("\"max\":").append(max);
        }
        sb.append("}");
        return sb.toString();
    }
    if (type.equals(ResultType.ResolutionT.INSTANCE)) {
        return type.printNullable(settings, obj);
    }
    if (obj instanceof Collection) {
        Collection<?> col = (Collection<?>) obj;
        // Workaround: Arrow deserializes lists as a JsonStringArrayList which has a JSON String method
        new StringJoiner(",", "[", "]");
        @NonNull ResultType elemType = ((ResultType.ListT) type).getElementType();
        return col.stream().map(v -> getPrintValue(v, elemType, settings)).collect(Collectors.joining(", ", "[", "]"));
    }
    return obj.toString();
}
Also used : ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ArrowType(org.apache.arrow.vector.types.pojo.ArrowType) EntityResult(com.bakdata.conquery.models.query.results.EntityResult) ArrayList(java.util.ArrayList) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) EntityPrintId(com.bakdata.conquery.models.identifiable.mapping.EntityPrintId) ByteArrayInputStream(java.io.ByteArrayInputStream) FloatingPointPrecision(org.apache.arrow.vector.types.FloatingPointPrecision) ArrowRenderer(com.bakdata.conquery.io.result.arrow.ArrowRenderer) CDate(com.bakdata.conquery.models.common.CDate) Locale(java.util.Locale) I18n(com.bakdata.conquery.models.i18n.I18n) ArrowStreamReader(org.apache.arrow.vector.ipc.ArrowStreamReader) ResultType(com.bakdata.conquery.models.externalservice.ResultType) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) DictionaryProvider(org.apache.arrow.vector.dictionary.DictionaryProvider) UniqueNamer(com.bakdata.conquery.models.query.resultinfo.UniqueNamer) FieldVector(org.apache.arrow.vector.FieldVector) SelectResultInfo(com.bakdata.conquery.models.query.resultinfo.SelectResultInfo) NonNull(lombok.NonNull) VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) FieldType(org.apache.arrow.vector.types.pojo.FieldType) Collection(java.util.Collection) IOException(java.io.IOException) Field(org.apache.arrow.vector.types.pojo.Field) Collectors(java.util.stream.Collectors) ArrowStreamWriter(org.apache.arrow.vector.ipc.ArrowStreamWriter) JsonStringArrayList(org.apache.arrow.vector.util.JsonStringArrayList) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) ResultTestUtil(com.bakdata.conquery.io.result.ResultTestUtil) StringJoiner(java.util.StringJoiner) ROOT_ALLOCATOR(com.bakdata.conquery.io.result.arrow.ArrowUtil.ROOT_ALLOCATOR) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) DateUnit(org.apache.arrow.vector.types.DateUnit) InputStream(java.io.InputStream) NonNull(lombok.NonNull) Collection(java.util.Collection) ArrayList(java.util.ArrayList) JsonStringArrayList(org.apache.arrow.vector.util.JsonStringArrayList) List(java.util.List) ResultType(com.bakdata.conquery.models.externalservice.ResultType) StringJoiner(java.util.StringJoiner)

Aggregations

JsonStringArrayList (org.apache.arrow.vector.util.JsonStringArrayList)4 BigQueryResult (com.google.cloud.bigquery.BigQueryResult)3 Connection (com.google.cloud.bigquery.Connection)3 ResultSet (java.sql.ResultSet)3 Test (org.junit.Test)3 CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)1 ResultTestUtil (com.bakdata.conquery.io.result.ResultTestUtil)1 ArrowRenderer (com.bakdata.conquery.io.result.arrow.ArrowRenderer)1 ROOT_ALLOCATOR (com.bakdata.conquery.io.result.arrow.ArrowUtil.ROOT_ALLOCATOR)1 CDate (com.bakdata.conquery.models.common.CDate)1 ConqueryConfig (com.bakdata.conquery.models.config.ConqueryConfig)1 ResultType (com.bakdata.conquery.models.externalservice.ResultType)1 I18n (com.bakdata.conquery.models.i18n.I18n)1 EntityPrintId (com.bakdata.conquery.models.identifiable.mapping.EntityPrintId)1 ManagedQuery (com.bakdata.conquery.models.query.ManagedQuery)1 PrintSettings (com.bakdata.conquery.models.query.PrintSettings)1 ResultInfo (com.bakdata.conquery.models.query.resultinfo.ResultInfo)1 SelectResultInfo (com.bakdata.conquery.models.query.resultinfo.SelectResultInfo)1 UniqueNamer (com.bakdata.conquery.models.query.resultinfo.UniqueNamer)1 EntityResult (com.bakdata.conquery.models.query.results.EntityResult)1