From 74134f1d981cfe693ff3e7c1defa8b3d97c154f6 Mon Sep 17 00:00:00 2001 From: Dmitry Kropachev Date: Mon, 13 Jul 2026 18:11:59 -0400 Subject: [PATCH 1/2] DRIVER-787: start SELECT without FROM validation From 69fa4a5209962a807165284761bb33f142a3702c Mon Sep 17 00:00:00 2001 From: Dmitry Kropachev Date: Mon, 13 Jul 2026 19:43:14 -0400 Subject: [PATCH 2/2] test: cover SELECT without FROM --- .../driver/core/SelectWithoutFromTest.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 driver-core/src/test/java/com/datastax/driver/core/SelectWithoutFromTest.java diff --git a/driver-core/src/test/java/com/datastax/driver/core/SelectWithoutFromTest.java b/driver-core/src/test/java/com/datastax/driver/core/SelectWithoutFromTest.java new file mode 100644 index 00000000000..db005c944e3 --- /dev/null +++ b/driver-core/src/test/java/com/datastax/driver/core/SelectWithoutFromTest.java @@ -0,0 +1,65 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.datastax.driver.core; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.datastax.driver.core.exceptions.InvalidQueryException; +import com.datastax.driver.core.exceptions.SyntaxError; +import org.testng.SkipException; +import org.testng.annotations.Test; + +public class SelectWithoutFromTest extends CCMTestsSupport { + + @Test(groups = "short") + public void should_execute_select_without_from() { + ResultSet result; + try { + result = session().execute("SELECT 1"); + } catch (InvalidQueryException | SyntaxError e) { + throw new SkipException("Server does not support SELECT without FROM", e); + } + + assertLiteralResult(result); + assertNowResult(session().execute("SELECT now()")); + + PreparedStatement prepared = session().prepare("SELECT 1"); + assertLiteralResult(session().execute(prepared.bind())); + + prepared = session().prepare("SELECT now()"); + assertNowResult(session().execute(prepared.bind())); + } + + private static void assertLiteralResult(ResultSet result) { + Row row = result.one(); + assertThat(row).isNotNull(); + ColumnDefinitions definitions = result.getColumnDefinitions(); + assertThat(definitions.size()).isEqualTo(1); + assertThat(definitions.getName(0)).isEqualTo("1"); + assertThat(definitions.getType(0)).isEqualTo(DataType.cint()); + assertThat(row.getInt(0)).isEqualTo(1); + } + + private static void assertNowResult(ResultSet result) { + Row row = result.one(); + assertThat(row).isNotNull(); + ColumnDefinitions definitions = result.getColumnDefinitions(); + assertThat(definitions.size()).isEqualTo(1); + assertThat(definitions.getName(0)).isEqualTo("now()"); + assertThat(definitions.getType(0)).isEqualTo(DataType.timeuuid()); + assertThat(row.getUUID(0)).isNotNull(); + } +}