Search in sources :

Example 1 with QueryExtractor

use of com.hazelcast.sql.impl.extract.QueryExtractor in project hazelcast by hazelcast.

the class CsvQueryTargetTest method test_get.

@Test
public void test_get() {
    QueryTarget target = new CsvQueryTarget(asList("nonExisting", "string", "boolean", "byte", "short", "int", "long", "float", "double", "decimal", "time", "date", "timestamp", "timestampTz", "object"));
    QueryExtractor topExtractor = target.createExtractor(null, OBJECT);
    QueryExtractor nonExistingExtractor = target.createExtractor("nonExisting", OBJECT);
    QueryExtractor stringExtractor = target.createExtractor("string", VARCHAR);
    QueryExtractor booleanExtractor = target.createExtractor("boolean", BOOLEAN);
    QueryExtractor byteExtractor = target.createExtractor("byte", TINYINT);
    QueryExtractor shortExtractor = target.createExtractor("short", SMALLINT);
    QueryExtractor intExtractor = target.createExtractor("int", INT);
    QueryExtractor longExtractor = target.createExtractor("long", BIGINT);
    QueryExtractor floatExtractor = target.createExtractor("float", REAL);
    QueryExtractor doubleExtractor = target.createExtractor("double", DOUBLE);
    QueryExtractor decimalExtractor = target.createExtractor("decimal", DECIMAL);
    QueryExtractor timeExtractor = target.createExtractor("time", TIME);
    QueryExtractor dateExtractor = target.createExtractor("date", DATE);
    QueryExtractor timestampExtractor = target.createExtractor("timestamp", TIMESTAMP);
    QueryExtractor timestampTzExtractor = target.createExtractor("timestampTz", TIMESTAMP_WITH_TZ_OFFSET_DATE_TIME);
    QueryExtractor objectExtractor = target.createExtractor("object", OBJECT);
    target.setTarget(new String[] { null, "string", "true", "127", "32767", "2147483647", "9223372036854775807", "1234567890.1", "123451234567890.1", "9223372036854775.123", "12:23:34", "2020-09-09", "2020-09-09T12:23:34.100", "2020-09-09T12:23:34.200Z", "object" }, null);
    assertThat(topExtractor.get()).isInstanceOf(String[].class);
    assertThat(nonExistingExtractor.get()).isNull();
    assertThat(stringExtractor.get()).isEqualTo("string");
    assertThat(booleanExtractor.get()).isEqualTo(true);
    assertThat(byteExtractor.get()).isEqualTo((byte) 127);
    assertThat(shortExtractor.get()).isEqualTo((short) 32767);
    assertThat(intExtractor.get()).isEqualTo(2147483647);
    assertThat(longExtractor.get()).isEqualTo(9223372036854775807L);
    assertThat(floatExtractor.get()).isEqualTo(1234567890.1F);
    assertThat(doubleExtractor.get()).isEqualTo(123451234567890.1D);
    assertThat(decimalExtractor.get()).isEqualTo(new BigDecimal("9223372036854775.123"));
    assertThat(timeExtractor.get()).isEqualTo(LocalTime.of(12, 23, 34));
    assertThat(dateExtractor.get()).isEqualTo(LocalDate.of(2020, 9, 9));
    assertThat(timestampExtractor.get()).isEqualTo(LocalDateTime.of(2020, 9, 9, 12, 23, 34, 100_000_000));
    assertThat(timestampTzExtractor.get()).isEqualTo(OffsetDateTime.of(2020, 9, 9, 12, 23, 34, 200_000_000, UTC));
    assertThat(objectExtractor.get()).isNotNull();
}
Also used : QueryTarget(com.hazelcast.sql.impl.extract.QueryTarget) BigDecimal(java.math.BigDecimal) QueryExtractor(com.hazelcast.sql.impl.extract.QueryExtractor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with QueryExtractor

use of com.hazelcast.sql.impl.extract.QueryExtractor in project hazelcast by hazelcast.

the class HazelcastJsonQueryTargetTest method test_get.

@Test
@Parameters(method = "values")
public void test_get(Object value) {
    Extractors extractors = Extractors.newBuilder(SERIALIZATION_SERVICE).build();
    QueryTarget target = new HazelcastJsonQueryTarget(SERIALIZATION_SERVICE, extractors, true);
    QueryExtractor topExtractor = target.createExtractor(null, OBJECT);
    QueryExtractor nonExistingExtractor = target.createExtractor("nonExisting", OBJECT);
    QueryExtractor stringExtractor = target.createExtractor("string", VARCHAR);
    QueryExtractor booleanExtractor = target.createExtractor("boolean", BOOLEAN);
    QueryExtractor byteExtractor = target.createExtractor("byte", TINYINT);
    QueryExtractor shortExtractor = target.createExtractor("short", SMALLINT);
    QueryExtractor intExtractor = target.createExtractor("int", INT);
    QueryExtractor longExtractor = target.createExtractor("long", BIGINT);
    QueryExtractor floatExtractor = target.createExtractor("float", REAL);
    QueryExtractor doubleExtractor = target.createExtractor("double", DOUBLE);
    QueryExtractor decimalExtractor = target.createExtractor("decimal", DECIMAL);
    QueryExtractor timeExtractor = target.createExtractor("time", TIME);
    QueryExtractor dateExtractor = target.createExtractor("date", DATE);
    QueryExtractor timestampExtractor = target.createExtractor("timestamp", TIMESTAMP);
    QueryExtractor timestampZoneExtractor = target.createExtractor("timestampTz", TIMESTAMP_WITH_TZ_OFFSET_DATE_TIME);
    QueryExtractor nullExtractor = target.createExtractor("null", OBJECT);
    QueryExtractor objectExtractor = target.createExtractor("object", OBJECT);
    target.setTarget(value, null);
    assertThat(topExtractor.get()).isInstanceOf(HazelcastJsonValue.class);
    assertThat(nonExistingExtractor.get()).isNull();
    assertThat(stringExtractor.get()).isEqualTo("string");
    assertThat(booleanExtractor.get()).isEqualTo(true);
    assertThat(byteExtractor.get()).isEqualTo((byte) 127);
    assertThat(shortExtractor.get()).isEqualTo((short) 32767);
    assertThat(intExtractor.get()).isEqualTo(2147483647);
    assertThat(longExtractor.get()).isEqualTo(9223372036854775807L);
    assertThat(floatExtractor.get()).isEqualTo(1234567890.1F);
    assertThat(doubleExtractor.get()).isEqualTo(123451234567890.1D);
    assertThat(decimalExtractor.get()).isEqualTo(new BigDecimal("9223372036854775.123"));
    assertThat(timeExtractor.get()).isEqualTo(LocalTime.of(12, 23, 34));
    assertThat(dateExtractor.get()).isEqualTo(LocalDate.of(2020, 9, 9));
    assertThat(timestampExtractor.get()).isEqualTo(LocalDateTime.of(2020, 9, 9, 12, 23, 34, 100_000_000));
    assertThat(timestampZoneExtractor.get()).isEqualTo(OffsetDateTime.of(2020, 9, 9, 12, 23, 34, 200_000_000, UTC));
    assertThat(nullExtractor.get()).isNull();
    assertThat(objectExtractor.get()).isNotNull();
}
Also used : QueryTarget(com.hazelcast.sql.impl.extract.QueryTarget) Extractors(com.hazelcast.query.impl.getters.Extractors) BigDecimal(java.math.BigDecimal) QueryExtractor(com.hazelcast.sql.impl.extract.QueryExtractor) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 3 with QueryExtractor

use of com.hazelcast.sql.impl.extract.QueryExtractor in project hazelcast by hazelcast.

the class MapScanRow method create.

public static MapScanRow create(QueryTargetDescriptor keyDescriptor, QueryTargetDescriptor valueDescriptor, List<QueryPath> fieldPaths, List<QueryDataType> fieldTypes, Extractors extractors, InternalSerializationService serializationService) {
    QueryTarget keyTarget = keyDescriptor.create(serializationService, extractors, true);
    QueryTarget valueTarget = valueDescriptor.create(serializationService, extractors, false);
    QueryExtractor[] fieldExtractors = new QueryExtractor[fieldPaths.size()];
    for (int i = 0; i < fieldPaths.size(); i++) {
        QueryPath fieldPath = fieldPaths.get(i);
        QueryDataType fieldType = fieldTypes.get(i);
        fieldExtractors[i] = createExtractor(keyTarget, valueTarget, fieldPath, fieldType);
    }
    return new MapScanRow(keyTarget, valueTarget, fieldExtractors);
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) QueryTarget(com.hazelcast.sql.impl.extract.QueryTarget) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) QueryExtractor(com.hazelcast.sql.impl.extract.QueryExtractor)

Example 4 with QueryExtractor

use of com.hazelcast.sql.impl.extract.QueryExtractor in project hazelcast by hazelcast.

the class AvroQueryTargetTest method test_get.

@Test
public void test_get() {
    QueryTarget target = new AvroQueryTarget();
    QueryExtractor topExtractor = target.createExtractor(null, OBJECT);
    QueryExtractor nonExistingExtractor = target.createExtractor("nonExisting", OBJECT);
    QueryExtractor stringExtractor = target.createExtractor("string", VARCHAR);
    QueryExtractor booleanExtractor = target.createExtractor("boolean", BOOLEAN);
    QueryExtractor byteExtractor = target.createExtractor("byte", TINYINT);
    QueryExtractor shortExtractor = target.createExtractor("short", SMALLINT);
    QueryExtractor intExtractor = target.createExtractor("int", INT);
    QueryExtractor longExtractor = target.createExtractor("long", BIGINT);
    QueryExtractor floatExtractor = target.createExtractor("float", REAL);
    QueryExtractor doubleExtractor = target.createExtractor("double", DOUBLE);
    QueryExtractor decimalExtractor = target.createExtractor("decimal", DECIMAL);
    QueryExtractor timeExtractor = target.createExtractor("time", TIME);
    QueryExtractor dateExtractor = target.createExtractor("date", DATE);
    QueryExtractor timestampExtractor = target.createExtractor("timestamp", TIMESTAMP);
    QueryExtractor timestampTzExtractor = target.createExtractor("timestampTz", TIMESTAMP_WITH_TZ_OFFSET_DATE_TIME);
    QueryExtractor nullExtractor = target.createExtractor("null", OBJECT);
    QueryExtractor objectExtractor = target.createExtractor("object", OBJECT);
    Schema schema = SchemaBuilder.record("name").fields().name("string").type().stringType().noDefault().name("boolean").type().booleanType().noDefault().name("byte").type().intType().noDefault().name("short").type().intType().noDefault().name("int").type().intType().noDefault().name("long").type().longType().noDefault().name("float").type().floatType().noDefault().name("double").type().doubleType().noDefault().name("decimal").type().stringType().noDefault().name("time").type().stringType().noDefault().name("date").type().stringType().noDefault().name("timestamp").type().stringType().noDefault().name("timestampTz").type().stringType().noDefault().name("null").type().nullable().record("nul").fields().endRecord().noDefault().name("object").type().record("object").fields().endRecord().noDefault().endRecord();
    target.setTarget(new GenericRecordBuilder(schema).set("string", "string").set("boolean", true).set("byte", (byte) 127).set("short", (short) 32767).set("int", 2147483647).set("long", 9223372036854775807L).set("float", 1234567890.1F).set("double", 123451234567890.1D).set("decimal", "9223372036854775.123").set("time", "12:23:34").set("date", "2020-09-09").set("timestamp", "2020-09-09T12:23:34.1").set("timestampTz", "2020-09-09T12:23:34.2Z").set("null", null).set("object", new GenericRecordBuilder(SchemaBuilder.record("name").fields().endRecord()).build()).build(), null);
    assertThat(topExtractor.get()).isInstanceOf(GenericRecord.class);
    assertThat(nonExistingExtractor.get()).isNull();
    assertThat(stringExtractor.get()).isEqualTo("string");
    assertThat(booleanExtractor.get()).isEqualTo(true);
    assertThat(byteExtractor.get()).isEqualTo((byte) 127);
    assertThat(shortExtractor.get()).isEqualTo((short) 32767);
    assertThat(intExtractor.get()).isEqualTo(2147483647);
    assertThat(longExtractor.get()).isEqualTo(9223372036854775807L);
    assertThat(floatExtractor.get()).isEqualTo(1234567890.1F);
    assertThat(doubleExtractor.get()).isEqualTo(123451234567890.1D);
    assertThat(decimalExtractor.get()).isEqualTo(new BigDecimal("9223372036854775.123"));
    assertThat(timeExtractor.get()).isEqualTo(LocalTime.of(12, 23, 34));
    assertThat(dateExtractor.get()).isEqualTo(LocalDate.of(2020, 9, 9));
    assertThat(timestampExtractor.get()).isEqualTo(LocalDateTime.of(2020, 9, 9, 12, 23, 34, 100_000_000));
    assertThat(timestampTzExtractor.get()).isEqualTo(OffsetDateTime.of(2020, 9, 9, 12, 23, 34, 200_000_000, UTC));
    assertThat(nullExtractor.get()).isNull();
    assertThat(objectExtractor.get()).isNotNull();
}
Also used : QueryTarget(com.hazelcast.sql.impl.extract.QueryTarget) Schema(org.apache.avro.Schema) GenericRecordBuilder(org.apache.avro.generic.GenericRecordBuilder) BigDecimal(java.math.BigDecimal) QueryExtractor(com.hazelcast.sql.impl.extract.QueryExtractor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with QueryExtractor

use of com.hazelcast.sql.impl.extract.QueryExtractor in project hazelcast by hazelcast.

the class JsonQueryTargetTest method test_get.

@Test
@Parameters(method = "values")
public void test_get(Object value) {
    QueryTarget target = new JsonQueryTarget();
    QueryExtractor topExtractor = target.createExtractor(null, OBJECT);
    QueryExtractor nonExistingExtractor = target.createExtractor("nonExisting", OBJECT);
    QueryExtractor stringExtractor = target.createExtractor("string", VARCHAR);
    QueryExtractor booleanExtractor = target.createExtractor("boolean", BOOLEAN);
    QueryExtractor byteExtractor = target.createExtractor("byte", TINYINT);
    QueryExtractor shortExtractor = target.createExtractor("short", SMALLINT);
    QueryExtractor intExtractor = target.createExtractor("int", INT);
    QueryExtractor longExtractor = target.createExtractor("long", BIGINT);
    QueryExtractor floatExtractor = target.createExtractor("float", REAL);
    QueryExtractor doubleExtractor = target.createExtractor("double", DOUBLE);
    QueryExtractor decimalExtractor = target.createExtractor("decimal", DECIMAL);
    QueryExtractor timeExtractor = target.createExtractor("time", TIME);
    QueryExtractor dateExtractor = target.createExtractor("date", DATE);
    QueryExtractor timestampExtractor = target.createExtractor("timestamp", TIMESTAMP);
    QueryExtractor timestampTzExtractor = target.createExtractor("timestampTz", TIMESTAMP_WITH_TZ_OFFSET_DATE_TIME);
    QueryExtractor nullExtractor = target.createExtractor("null", OBJECT);
    QueryExtractor objectExtractor = target.createExtractor("object", OBJECT);
    target.setTarget(value, null);
    assertThat(topExtractor.get()).isInstanceOf(Map.class);
    assertThat(nonExistingExtractor.get()).isNull();
    assertThat(stringExtractor.get()).isEqualTo("string");
    assertThat(booleanExtractor.get()).isEqualTo(true);
    assertThat(byteExtractor.get()).isEqualTo((byte) 127);
    assertThat(shortExtractor.get()).isEqualTo((short) 32767);
    assertThat(intExtractor.get()).isEqualTo(2147483647);
    assertThat(longExtractor.get()).isEqualTo(9223372036854775807L);
    assertThat(floatExtractor.get()).isEqualTo(1234567890.1F);
    assertThat(doubleExtractor.get()).isEqualTo(123451234567890.1D);
    assertThat(decimalExtractor.get()).isEqualTo(new BigDecimal("9223372036854775.123"));
    assertThat(timeExtractor.get()).isEqualTo(LocalTime.of(12, 23, 34));
    assertThat(dateExtractor.get()).isEqualTo(LocalDate.of(2020, 9, 9));
    assertThat(timestampExtractor.get()).isEqualTo(LocalDateTime.of(2020, 9, 9, 12, 23, 34, 100_000_000));
    assertThat(timestampTzExtractor.get()).isEqualTo(OffsetDateTime.of(2020, 9, 9, 12, 23, 34, 200_000_000, UTC));
    assertThat(nullExtractor.get()).isNull();
    assertThat(objectExtractor.get()).isNotNull();
}
Also used : QueryTarget(com.hazelcast.sql.impl.extract.QueryTarget) BigDecimal(java.math.BigDecimal) QueryExtractor(com.hazelcast.sql.impl.extract.QueryExtractor) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

QueryExtractor (com.hazelcast.sql.impl.extract.QueryExtractor)7 QueryTarget (com.hazelcast.sql.impl.extract.QueryTarget)5 BigDecimal (java.math.BigDecimal)4 Test (org.junit.Test)4 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)3 QueryPath (com.hazelcast.sql.impl.extract.QueryPath)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Parameters (junitparams.Parameters)2 Extractors (com.hazelcast.query.impl.getters.Extractors)1 Schema (org.apache.avro.Schema)1 GenericRecordBuilder (org.apache.avro.generic.GenericRecordBuilder)1