use of com.hazelcast.sql.SqlColumnType in project hazelcast by hazelcast.
the class BetweenOperatorIntegrationTest method checkSuccessOrFailure.
protected void checkSuccessOrFailure(String sql, Tuple2<List<SqlRow>, HazelcastSqlException> expectedOutcome, Object... params) {
try {
List<SqlRow> rows = execute(sql, params);
assertNull(expectedOutcome.f1());
assertEquals(expectedOutcome.f0().size(), rows.size());
List<SqlRow> expectedResultsList = expectedOutcome.f0();
for (int i = 0; i < rows.size(); i++) {
SqlColumnType expectedType = expectedResultsList.get(i).getMetadata().getColumn(0).getType();
SqlColumnType actualType = rows.get(i).getMetadata().getColumn(0).getType();
assertEquals(expectedType, actualType);
Object actualObject = rows.get(i).getObject(0);
Object expectedObject = expectedResultsList.get(i).getObject(0);
assertEquals(expectedObject, actualObject);
}
} catch (HazelcastSqlException e) {
assertNotNull(expectedOutcome.f1());
// Expected :At line 1, column [5]5: ...
// Actual :At line 1, column [6]5: ...
// To overcome this ^ we are comparing substrings like
// "Parameter at position 1 must be of $1 type, but $2 was found (consider adding an explicit CAST)"
//
// Expected :The Jet SQL job failed: Execution on a member failed: com.hazelcast.jet.JetException: Exception in ProcessorTasklet{06bd-fcd0-9e82-0001/Project(IMap[public.map])#1}: com.hazelcast.sql.impl.QueryException: ...
// Actual :The Jet SQL job failed: Execution on a member failed: com.hazelcast.jet.JetException: Exception in ProcessorTasklet{06bd-fcd0-9e83-0001/Project(IMap[public.map])#1}: com.hazelcast.sql.impl.QueryException: ...
// To overcome this ^ we are comparing substrings like
// "Cannot compare two OBJECT values, because left operand has class com.hazelcast.jet.sql.impl.support.expressions.ExpressionType$ObjectHolder type and right operand has class java.lang.String type
int startIndex = e.getMessage().indexOf("Parameter");
if (startIndex == -1) {
startIndex = e.getMessage().indexOf("Cannot compare");
}
assertEquals(expectedOutcome.f1().getMessage().substring(startIndex), e.getMessage().substring(startIndex));
}
}
use of com.hazelcast.sql.SqlColumnType in project hazelcast by hazelcast.
the class BetweenOperatorIntegrationTest method checkValues.
protected void checkValues(String sql, SqlColumnType expectedType, Object[] expectedResults, Object... params) {
List<SqlRow> rows = execute(sql, params);
assertEquals(expectedResults.length, rows.size());
if (rows.size() == 0) {
return;
}
if (rows.get(0).getObject(0) instanceof Integer) {
rows.sort(Comparator.comparingInt(a -> a.getObject(0)));
} else if (rows.get(0).getObject(0) instanceof Comparable) {
rows.sort((a, b) -> ((Comparable<?>) a.getObject(0)).compareTo(b.getObject(0)));
}
for (int i = 0; i < expectedResults.length; i++) {
SqlRow row = rows.get(i);
assertEquals(expectedType, row.getMetadata().getColumn(0).getType());
assertEquals(expectedResults[i], row.getObject(0));
}
}
use of com.hazelcast.sql.SqlColumnType in project hazelcast by hazelcast.
the class ComparisonPredicateIntegrationTest method checkNumeric.
private void checkNumeric(Object value1, Object value2) {
int res = compareNumeric(value1, value2);
if (res == RES_EQ && (value1 instanceof Float || value1 instanceof Double || value2 instanceof Float || value2 instanceof Double)) {
return;
}
ExpressionType<?> valueType1 = ExpressionTypes.resolve(value1);
ExpressionType<?> valueType2 = ExpressionTypes.resolve(value2);
Class<? extends ExpressionValue> class1 = ExpressionValue.createClass(valueType1);
Class<? extends ExpressionValue> class2 = ExpressionValue.createClass(valueType2);
Class<? extends ExpressionBiValue> biClass = ExpressionBiValue.createBiClass(valueType1, valueType2);
String literal1 = value1.toString();
String literal2 = value2.toString();
QueryDataType type1 = QueryDataTypeUtils.resolveTypeForClass(value1.getClass());
QueryDataType type2 = QueryDataTypeUtils.resolveTypeForClass(value2.getClass());
SqlColumnType publicType1 = type1.getTypeFamily().getPublicType();
SqlColumnType publicType2 = type2.getTypeFamily().getPublicType();
int precedence1 = type1.getTypeFamily().getPrecedence();
int precedence2 = type2.getTypeFamily().getPrecedence();
// Column/column
putCheckCommute(ExpressionBiValue.createBiValue(biClass, value1, value2), "field1", "field2", res);
putCheckCommute(ExpressionBiValue.createBiValue(biClass, value1, null), "field1", "field2", RES_NULL);
putCheckCommute(ExpressionBiValue.createBiValue(biClass, null, value2), "field1", "field2", RES_NULL);
// Column/literal
putCheckCommute(ExpressionValue.create(class1, value1), "field1", literal2, res);
putCheckCommute(ExpressionValue.create(class2, value2), literal1, "field1", res);
// Column/parameter
if (precedence1 >= precedence2) {
putCheckCommute(ExpressionValue.create(class1, value1), "field1", "?", res, value2);
} else if (precedence1 >= QueryDataType.BIGINT.getTypeFamily().getPrecedence()) {
putAndCheckFailure(ExpressionValue.create(class1, value1), sql(mode.token(), "field1", "?"), SqlErrorCode.DATA_EXCEPTION, parameterError(0, publicType1, publicType2), value2);
}
if (precedence2 >= precedence1) {
putCheckCommute(ExpressionValue.create(class2, value2), "?", "field1", res, value1);
} else if (precedence2 >= QueryDataType.BIGINT.getTypeFamily().getPrecedence()) {
putAndCheckFailure(ExpressionValue.create(class2, value2), sql(mode.token(), "?", "field1"), SqlErrorCode.DATA_EXCEPTION, parameterError(0, publicType2, publicType1), value1);
}
// Literal/literal
checkCommute(literal1, literal2, res);
}
use of com.hazelcast.sql.SqlColumnType in project hazelcast by hazelcast.
the class ComparisonPredicateIntegrationTest method testNumeric.
@Test(timeout = 600_000)
public void testNumeric() {
Object[] values = getNumericValues();
for (int i = 0; i < values.length; i++) {
for (int j = i; j < values.length; j++) {
checkNumeric(values[i], values[j]);
}
}
for (ExpressionType type : ExpressionTypes.numeric()) {
// Column/column
checkUnsupportedColumnColumn(type, ExpressionTypes.allExcept(ExpressionTypes.numeric()));
// Column/literal
SqlColumnType columnType = type.getFieldConverterType().getTypeFamily().getPublicType();
checkUnsupportedColumnLiteral(type.valueFrom(), columnType, LITERAL_VARCHAR, LITERAL_BOOLEAN);
// Column/parameter
if (type.getFieldConverterType().getTypeFamily().getPrecedence() >= QueryDataType.BIGINT.getTypeFamily().getPrecedence()) {
checkUnsupportedColumnParameter(type.valueFrom(), columnType, 0, ExpressionTypes.allExcept(ExpressionTypes.numeric()));
}
}
}
use of com.hazelcast.sql.SqlColumnType in project hazelcast by hazelcast.
the class SqlConsole method determineAlignments.
private static Alignment[] determineAlignments(SqlRowMetadata metadata) {
int colCount = metadata.getColumnCount();
Alignment[] alignments = new Alignment[colCount];
for (int i = 0; i < colCount; i++) {
SqlColumnMetadata colMetadata = metadata.getColumn(i);
SqlColumnType type = colMetadata.getType();
switch(type) {
case BIGINT:
case DECIMAL:
case DOUBLE:
case INTEGER:
case REAL:
case SMALLINT:
case TINYINT:
alignments[i] = Alignment.RIGHT;
break;
case BOOLEAN:
case DATE:
case NULL:
case OBJECT:
case TIMESTAMP:
case VARCHAR:
case TIMESTAMP_WITH_TIME_ZONE:
default:
alignments[i] = Alignment.LEFT;
}
}
return alignments;
}
Aggregations