use of com.hazelcast.sql.HazelcastSqlException in project hazelcast by hazelcast.
the class SqlErrorTest method testMemberLeaveDuringQueryAfterImmediateShutdown.
@Test
public void testMemberLeaveDuringQueryAfterImmediateShutdown() {
// Start two instances
instance1 = newHazelcastInstance(false);
instance2 = newHazelcastInstance(true);
SqlStatement streamingQuery = new SqlStatement("SELECT * FROM TABLE(GENERATE_STREAM(1000))");
// Start query with immediate shutdown afterwards
HazelcastSqlException error = assertSqlExceptionWithShutdown(instance1, streamingQuery);
assertInstanceOf(HazelcastInstanceNotActiveException.class, findRootCause(error));
}
use of com.hazelcast.sql.HazelcastSqlException in project hazelcast by hazelcast.
the class SqlErrorTest method testExecuteOnLiteMember.
@Test
public void testExecuteOnLiteMember() {
// Start one normal member and one local member.
newHazelcastInstance(true);
HazelcastInstance liteMember = factory.newHazelcastInstance(getConfig().setLiteMember(true));
// Insert data
populate(liteMember);
// Try query from the lite member.
HazelcastSqlException error = assertSqlException(liteMember, query());
assertErrorCode(SqlErrorCode.GENERIC, error);
assertEquals("SQL queries cannot be executed on lite members", error.getMessage());
}
use of com.hazelcast.sql.HazelcastSqlException in project hazelcast by hazelcast.
the class SqlConsole method executeSqlCmd.
private static void executeSqlCmd(HazelcastInstance hz, String command, Terminal terminal, AtomicReference<SqlResult> activeSqlResult) {
PrintWriter out = terminal.writer();
try (SqlResult sqlResult = hz.getSql().execute(command)) {
activeSqlResult.set(sqlResult);
// if it's a result with an update count, just print it
if (sqlResult.updateCount() != -1) {
String message = new AttributedStringBuilder().style(AttributedStyle.BOLD.foreground(PRIMARY_COLOR)).append("OK").toAnsi();
out.println(message);
return;
}
SqlRowMetadata rowMetadata = sqlResult.getRowMetadata();
int[] colWidths = determineColumnWidths(rowMetadata);
Alignment[] alignments = determineAlignments(rowMetadata);
// this is a result with rows. Print the header and rows, watch for concurrent cancellation
printMetadataInfo(rowMetadata, colWidths, alignments, out);
int rowCount = 0;
for (SqlRow row : sqlResult) {
rowCount++;
printRow(row, colWidths, alignments, out);
}
// bottom line after all the rows
printSeparatorLine(sqlResult.getRowMetadata().getColumnCount(), colWidths, out);
String message = new AttributedStringBuilder().style(AttributedStyle.BOLD.foreground(PRIMARY_COLOR)).append(String.valueOf(rowCount)).append(" row(s) selected").toAnsi();
out.println(message);
} catch (HazelcastSqlException e) {
// the query failed to execute with HazelcastSqlException
String errorPrompt = new AttributedStringBuilder().style(AttributedStyle.BOLD.foreground(PRIMARY_COLOR)).append(e.getMessage()).toAnsi();
out.println(errorPrompt);
} catch (Exception e) {
// the query failed to execute with an unexpected exception
String unexpectedErrorPrompt = new AttributedStringBuilder().style(AttributedStyle.BOLD.foreground(PRIMARY_COLOR)).append("Encountered an unexpected exception while executing the query:\n").append(e.getMessage()).toAnsi();
out.println(unexpectedErrorPrompt);
e.printStackTrace(out);
}
}
use of com.hazelcast.sql.HazelcastSqlException in project hazelcast by hazelcast.
the class SqlIndexConverterMismatchTest method testMismatch.
/**
* @see MapIndexScanExecIterator#getIndexEntries
*/
@SuppressWarnings({ "StatementWithEmptyBody", "JavadocReference" })
@Ignore("https://github.com/hazelcast/hazelcast/issues/19287")
@Test
public void testMismatch() {
ExpressionBiValue value1 = new ExpressionBiValue.IntegerIntegerVal();
value1.field1(10);
value1.field2(10);
ExpressionBiValue value2 = new ExpressionBiValue.StringIntegerVal();
value2.field1("10");
value2.field2(10);
map.put(getLocalKey(member1, key -> key), value1);
map.put(getLocalKey(member2, key -> key), value2);
try {
try (SqlResult result = member1.getSql().execute("SELECT key FROM " + MAP_NAME + " WHERE field1=1")) {
for (SqlRow ignore : result) {
// No-op.
}
}
fail("Must fail!");
} catch (HazelcastSqlException e) {
assertEquals(SqlErrorCode.INDEX_INVALID, e.getCode());
Throwable ex = findRootQueryException(e);
assertEquals("Cannot use the index \"index\" of the IMap \"map\" because it has component \"field1\" of type VARCHAR, but INTEGER was expected", ex.getMessage());
}
}
use of com.hazelcast.sql.HazelcastSqlException 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));
}
}
Aggregations