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;
}
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());
}
Aggregations