Search in sources :

Example 1 with LazyTarget

use of com.hazelcast.sql.impl.LazyTarget in project hazelcast by hazelcast.

the class ColumnExpression method evalTop.

@Override
public Object evalTop(Row row, ExpressionEvalContext context) {
    Object res = row.get(index);
    if (res instanceof LazyTarget) {
        assert type.equals(QueryDataType.OBJECT);
        LazyTarget lazyTarget = (LazyTarget) res;
        res = lazyTarget.getDeserialized() != null ? lazyTarget.getDeserialized() : lazyTarget.getSerialized();
    }
    return res;
}
Also used : LazyTarget(com.hazelcast.sql.impl.LazyTarget)

Example 2 with LazyTarget

use of com.hazelcast.sql.impl.LazyTarget in project hazelcast by hazelcast.

the class GenericQueryTargetTest method checkTarget.

private void checkTarget(GenericQueryTarget target, TestObject originalObject, Object object) {
    // Set target.
    if (object instanceof Data) {
        target.setTarget(null, (Data) object);
    } else {
        target.setTarget(object, null);
    }
    // Good top-level extractor.
    QueryExtractor targetExtractor = target.createExtractor(null, QueryDataType.OBJECT);
    LazyTarget lazyTarget = (LazyTarget) targetExtractor.get();
    TestObject extractedObject = (TestObject) (lazyTarget.deserialize(new DefaultSerializationServiceBuilder().build()));
    assertEquals(originalObject.getField(), extractedObject.getField());
    assertEquals(originalObject.getField2(), extractedObject.getField2());
    // Bad top-level extractor.
    QueryExtractor badTargetExtractor = target.createExtractor(null, QueryDataType.INT);
    QueryException error = assertThrows(QueryException.class, badTargetExtractor::get);
    assertEquals(SqlErrorCode.DATA_EXCEPTION, error.getCode());
    assertTrue(error.getMessage().startsWith("Failed to extract map entry " + (target.isKey() ? "key" : "value")));
    // Good field extractor.
    QueryExtractor fieldExtractor = target.createExtractor("field", QueryDataType.OBJECT);
    int extractedField = (Integer) fieldExtractor.get();
    assertEquals(originalObject.getField(), extractedField);
    // Bad field extractor (type).
    QueryExtractor badFieldTypeExtractor = target.createExtractor("field", QueryDataType.BIGINT);
    error = assertThrows(QueryException.class, badFieldTypeExtractor::get);
    assertEquals(SqlErrorCode.DATA_EXCEPTION, error.getCode());
    assertTrue(error.getMessage().startsWith("Failed to extract map entry " + (target.isKey() ? "key" : "value") + " field"));
    // Bad field extractor (name).
    QueryExtractor badFieldNameExtractor = target.createExtractor("badField", QueryDataType.INT);
    assertNull(badFieldNameExtractor.get());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) QueryException(com.hazelcast.sql.impl.QueryException) LazyTarget(com.hazelcast.sql.impl.LazyTarget) Data(com.hazelcast.internal.serialization.Data)

Aggregations

LazyTarget (com.hazelcast.sql.impl.LazyTarget)2 Data (com.hazelcast.internal.serialization.Data)1 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)1 QueryException (com.hazelcast.sql.impl.QueryException)1