Search in sources :

Example 1 with HazelcastSqlException

use of com.hazelcast.sql.HazelcastSqlException in project hazelcast by hazelcast.

the class BetweenOperatorIntegrationTest method betweenSymmetricPredicateTypeCheckTest.

@Test
public void betweenSymmetricPredicateTypeCheckTest() {
    int cycleCounter = 0;
    for (ExpressionType<?> fieldType : TESTED_TYPES) {
        putAll(fieldType.nonNullValues().toArray());
        for (ExpressionType<?> lowerBoundType : TESTED_TYPES) {
            for (ExpressionType<?> upperBoundType : TESTED_TYPES) {
                ++cycleCounter;
                ExpressionBiValue biValue = ExpressionBiValue.createBiValue(lowerBoundType.valueFrom(), upperBoundType.valueTo());
                Tuple2<List<SqlRow>, HazelcastSqlException> comparisonEquivalentResult = executePossiblyFailingQuery(// the queries have extra spaces so that the errors are on the same positions
                "SELECT this FROM map WHERE (this >=     ? AND this <= ?) OR (this >= ? AND this <= ?) ORDER BY this", fieldType.getFieldConverterType().getTypeFamily().getPublicType(), biValue.field1(), biValue.field2(), biValue.field2(), biValue.field1());
                try {
                    checkSuccessOrFailure("SELECT this FROM map WHERE this BETWEEN SYMMETRIC ? AND         ?  ORDER BY this", comparisonEquivalentResult, biValue.field1(), biValue.field2());
                } catch (Throwable e) {
                    throw new AssertionError("For [" + fieldType + ", " + lowerBoundType + ", " + upperBoundType + "]: " + e, e);
                }
            }
        }
    }
    assertEquals(TESTED_TYPES.length * TESTED_TYPES.length * TESTED_TYPES.length, cycleCounter);
}
Also used : ExpressionBiValue(com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue) ArrayList(java.util.ArrayList) List(java.util.List) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with HazelcastSqlException

use of com.hazelcast.sql.HazelcastSqlException in project hazelcast by hazelcast.

the class BetweenOperatorIntegrationTest method betweenAsymmetricPredicateTypeCheckTest.

@Test
public void betweenAsymmetricPredicateTypeCheckTest() {
    for (ExpressionType<?> fieldType : TESTED_TYPES) {
        putAll(fieldType.nonNullValues().toArray());
        for (ExpressionType<?> lowerBoundType : TESTED_TYPES) {
            for (ExpressionType<?> upperBoundType : TESTED_TYPES) {
                ExpressionBiValue biValue = ExpressionBiValue.createBiValue(lowerBoundType.valueFrom(), upperBoundType.valueTo());
                Tuple2<List<SqlRow>, HazelcastSqlException> comparisonEquivalentResult = executePossiblyFailingQuery(// the queries have extra spaces so that the errors are on the same positions
                "SELECT this FROM map WHERE this >=      ? AND this <= ?  ORDER BY this", fieldType.getFieldConverterType().getTypeFamily().getPublicType(), biValue.field1(), biValue.field2());
                try {
                    checkSuccessOrFailure("SELECT this FROM map WHERE this BETWEEN ? AND         ?  ORDER BY this", comparisonEquivalentResult, biValue.field1(), biValue.field2());
                } catch (Throwable e) {
                    throw new AssertionError("For [" + fieldType + ", " + lowerBoundType + ", " + upperBoundType + "]: " + e, e);
                }
            }
        }
    }
}
Also used : ExpressionBiValue(com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue) ArrayList(java.util.ArrayList) List(java.util.List) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with HazelcastSqlException

use of com.hazelcast.sql.HazelcastSqlException in project hazelcast by hazelcast.

the class BetweenOperatorIntegrationTest method executePossiblyFailingQuery.

/**
 * Execute a query and return either the result, or the exception it threw.
 */
protected Tuple2<List<SqlRow>, HazelcastSqlException> executePossiblyFailingQuery(String sql, SqlColumnType firstColumnExpectedType, Object... params) {
    try {
        SqlResult result = instance().getSql().execute(sql, params);
        List<SqlRow> rows = new ArrayList<>();
        for (SqlRow row : result) {
            assertEquals(firstColumnExpectedType, row.getMetadata().getColumn(0).getType());
            rows.add(row);
        }
        return tuple2(rows, null);
    } catch (HazelcastSqlException e) {
        return tuple2(Collections.emptyList(), e);
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) SqlResult(com.hazelcast.sql.SqlResult) ArrayList(java.util.ArrayList) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException)

Example 4 with HazelcastSqlException

use of com.hazelcast.sql.HazelcastSqlException in project hazelcast by hazelcast.

the class SqlClientResultTest method checkSqlException.

private void checkSqlException(Runnable task, int expectedCode, String expectedMessage) {
    HazelcastSqlException err = assertThrows(HazelcastSqlException.class, task);
    assertEquals(expectedCode, err.getCode());
    assertTrue(err.getMessage(), err.getMessage().contains(expectedMessage));
}
Also used : HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException)

Example 5 with HazelcastSqlException

use of com.hazelcast.sql.HazelcastSqlException in project hazelcast by hazelcast.

the class SqlErrorClientTest method testMemberDisconnect_close.

@Test
public void testMemberDisconnect_close() {
    instance1 = newHazelcastInstance(true);
    client = newClient();
    createMapping(instance1, MAP_NAME, long.class, long.class);
    populate(instance1, DEFAULT_CURSOR_BUFFER_SIZE + 1);
    try {
        SqlResult result = client.getSql().execute(query());
        instance1.shutdown();
        for (SqlRow ignore : result) {
        // No-op.
        }
        result.close();
        fail("Should fail");
    } catch (HazelcastSqlException e) {
        assertErrorCode(SqlErrorCode.CONNECTION_PROBLEM, e);
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) SqlResult(com.hazelcast.sql.SqlResult) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

HazelcastSqlException (com.hazelcast.sql.HazelcastSqlException)23 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)11 QuickTest (com.hazelcast.test.annotation.QuickTest)11 Test (org.junit.Test)11 SqlRow (com.hazelcast.sql.SqlRow)8 SqlStatement (com.hazelcast.sql.SqlStatement)7 SqlResult (com.hazelcast.sql.SqlResult)6 ArrayList (java.util.ArrayList)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 ExpressionBiValue (com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue)3 List (java.util.List)3 SqlColumnType (com.hazelcast.sql.SqlColumnType)2 QueryException (com.hazelcast.sql.impl.QueryException)2 SqlFetchCodec (com.hazelcast.client.impl.protocol.codec.SqlFetchCodec)1 Config (com.hazelcast.config.Config)1 IndexConfig (com.hazelcast.config.IndexConfig)1 IndexType (com.hazelcast.config.IndexType)1 MapConfig (com.hazelcast.config.MapConfig)1 IMap (com.hazelcast.map.IMap)1 SqlColumnMetadata (com.hazelcast.sql.SqlColumnMetadata)1