use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.
the class CastFunctionIntegrationTest method testVarchar_char.
@Test
public void testVarchar_char() {
putAndCheckValue(new ExpressionValue.CharacterVal(), sql("field1", VARCHAR), VARCHAR, null);
putAndCheckValue('b', sql("this", VARCHAR), VARCHAR, "b");
putAndCheckFailure('b', sql("this", BOOLEAN), DATA_EXCEPTION, "Cannot parse VARCHAR value to BOOLEAN");
putAndCheckFailure('b', sql("this", TINYINT), DATA_EXCEPTION, "Cannot parse VARCHAR value to TINYINT");
putAndCheckFailure('b', sql("this", SMALLINT), DATA_EXCEPTION, "Cannot parse VARCHAR value to SMALLINT");
putAndCheckFailure('b', sql("this", INTEGER), DATA_EXCEPTION, "Cannot parse VARCHAR value to INTEGER");
putAndCheckFailure('b', sql("this", BIGINT), DATA_EXCEPTION, "Cannot parse VARCHAR value to BIGINT");
putAndCheckFailure('b', sql("this", DECIMAL), DATA_EXCEPTION, "Cannot parse VARCHAR value to DECIMAL");
putAndCheckFailure('b', sql("this", REAL), DATA_EXCEPTION, "Cannot parse VARCHAR value to REAL");
putAndCheckFailure('b', sql("this", DOUBLE), DATA_EXCEPTION, "Cannot parse VARCHAR value to DOUBLE");
putAndCheckFailure('b', sql("this", DATE), DATA_EXCEPTION, "Cannot parse VARCHAR value to DATE");
putAndCheckFailure('b', sql("this", TIME), DATA_EXCEPTION, "Cannot parse VARCHAR value to TIME");
putAndCheckFailure('b', sql("this", TIMESTAMP), DATA_EXCEPTION, "Cannot parse VARCHAR value to TIMESTAMP");
putAndCheckFailure('b', sql("this", TIMESTAMP_WITH_TIME_ZONE), DATA_EXCEPTION, "Cannot parse VARCHAR value to TIMESTAMP WITH TIME ZONE");
putAndCheckValue('b', sql("this", OBJECT), OBJECT, "b");
putAndCheckValue('b', sql("this", JSON), JSON, new HazelcastJsonValue("b"));
}
use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.
the class JsonValueFunctionIntegrationTest method initMultiTypeObject.
private void initMultiTypeObject() {
final MultiTypeObject value = new MultiTypeObject();
final String serializedValue;
try {
serializedValue = SERIALIZER.writeValueAsString(value);
} catch (JsonProcessingException e) {
throw new HazelcastException(e);
}
final IMap<Long, HazelcastJsonValue> test = instance().getMap("test");
test.put(1L, new HazelcastJsonValue(serializedValue));
}
use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.
the class JsonQueryFunction method eval.
@Override
public HazelcastJsonValue eval(final Row row, final ExpressionEvalContext context) {
// first evaluate the required parameter
final String path = (String) operands[1].eval(row, context);
if (path == null) {
throw QueryException.error("SQL/JSON path expression cannot be null");
}
final Object operand0 = operands[0].eval(row, context);
String json = operand0 instanceof HazelcastJsonValue ? operand0.toString() : (String) operand0;
if (json == null) {
json = "";
}
final JsonPath jsonPath;
try {
jsonPath = pathCache.asMap().computeIfAbsent(path, JsonPathUtil::compile);
} catch (JsonPathCompilerException e) {
// We deliberately don't use the cause here. The reason is that exceptions from ANTLR are not always
// serializable, they can contain references to parser context and other objects, which are not.
// That's why we also log the exception here.
LOGGER.fine("JSON_QUERY JsonPath compilation failed", e);
throw QueryException.error("Invalid SQL/JSON path expression: " + e.getMessage());
}
return wrap(execute(json, jsonPath));
}
use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.
the class SampleMetadataResolver method resolve.
@Nullable
@SuppressWarnings("checkstyle:returncount")
static Metadata resolve(InternalSerializationService ss, Object target, boolean key) {
try {
if (target instanceof Data) {
Data data = (Data) target;
if (data.isPortable()) {
ClassDefinition classDefinition = ss.getPortableContext().lookupClassDefinition(data);
return resolvePortable(classDefinition, key);
} else if (data.isCompact()) {
return resolveCompact(ss.extractSchemaFromData(data), key);
} else if (data.isJson()) {
return null;
} else {
return resolveJava(ss.toObject(data).getClass(), key);
}
} else if (target instanceof VersionedPortable) {
VersionedPortable portable = (VersionedPortable) target;
ClassDefinition classDefinition = ss.getPortableContext().lookupClassDefinition(portable.getFactoryId(), portable.getClassId(), portable.getClassVersion());
return resolvePortable(classDefinition, key);
} else if (target instanceof Portable) {
Portable portable = (Portable) target;
ClassDefinition classDefinition = ss.getPortableContext().lookupClassDefinition(portable.getFactoryId(), portable.getClassId(), 0);
return resolvePortable(classDefinition, key);
} else if (target instanceof PortableGenericRecord) {
return resolvePortable(((PortableGenericRecord) target).getClassDefinition(), key);
} else if (target instanceof CompactGenericRecord) {
return resolveCompact(((CompactGenericRecord) target).getSchema(), key);
} else if (ss.isCompactSerializable(target)) {
Schema schema = ss.extractSchemaFromObject(target);
return resolveCompact(schema, key);
} else if (target instanceof HazelcastJsonValue) {
return null;
} else {
return resolveJava(target.getClass(), key);
}
} catch (Exception e) {
return null;
}
}
Aggregations