Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions plugin/trino-cassandra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.trino.Session;
import io.trino.plugin.cassandra.TestCassandraTable.ColumnDefinition;
import io.trino.spi.type.RowType.Field;
import io.trino.spi.type.TimeZoneKey;
import io.trino.testing.AbstractTestQueryFramework;
Expand All @@ -26,6 +27,7 @@
import io.trino.testing.datatype.DataSetup;
import io.trino.testing.datatype.SqlDataTypeTest;
import io.trino.testing.sql.TrinoSqlExecutor;
import org.intellij.lang.annotations.Language;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
Expand All @@ -35,13 +37,16 @@
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.Function;

import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Verify.verify;
import static io.trino.plugin.cassandra.CassandraQueryRunner.createCassandraQueryRunner;
import static io.trino.plugin.cassandra.TestCassandraTable.generalColumn;
import static io.trino.plugin.cassandra.TestCassandraTable.partitionColumn;
import static io.trino.spi.type.BigintType.BIGINT;
import static io.trino.spi.type.BooleanType.BOOLEAN;
import static io.trino.spi.type.DateType.DATE;
Expand All @@ -59,6 +64,7 @@
import static io.trino.spi.type.VarcharType.createVarcharType;
import static java.lang.String.format;
import static java.time.ZoneOffset.UTC;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class TestCassandraTypeMapping
extends AbstractTestQueryFramework
Expand Down Expand Up @@ -162,6 +168,22 @@ public void testTinyint()
.execute(getQueryRunner(), trinoCreateAndInsert("test_tinyint"));
}

@Test
public void testUnsupportedTinyint()
{
try (TestCassandraTable table = testTable(
"test_unsupported_tinyint",
ImmutableList.of(partitionColumn("id", "tinyint"), generalColumn("data", "tinyint")),
ImmutableList.of())) {
assertCassandraQueryFails(
"INSERT INTO " + table.getTableName() + " (id, data) VALUES (1, -129)", // min - 1
"Unable to make byte from '-129'");
assertCassandraQueryFails(
"INSERT INTO " + table.getTableName() + " (id, data) VALUES (2, 128)", // max + 1
"Unable to make byte from '128'");
}
}

@Test
public void testSmallint()
{
Expand All @@ -175,6 +197,22 @@ public void testSmallint()
.execute(getQueryRunner(), trinoCreateAndInsert("test_smallint"));
}

@Test
public void testUnsupportedSmallint()
{
try (TestCassandraTable table = testTable(
"test_unsupported_smallint",
ImmutableList.of(partitionColumn("id", "smallint"), generalColumn("data", "smallint")),
ImmutableList.of())) {
assertCassandraQueryFails(
"INSERT INTO " + table.getTableName() + " (id, data) VALUES (1, -32769)", // min - 1
"Unable to make short from '-32769'");
assertCassandraQueryFails(
"INSERT INTO " + table.getTableName() + " (id, data) VALUES (2, 32768)", // max + 1
"Unable to make short from '32768'");
}
}

@Test
public void testInt()
{
Expand All @@ -188,6 +226,22 @@ public void testInt()
.execute(getQueryRunner(), trinoCreateAndInsert("test_int"));
}

@Test
public void testUnsupportedInt()
{
try (TestCassandraTable table = testTable(
"test_unsupported_int",
ImmutableList.of(partitionColumn("id", "int"), generalColumn("data", "int")),
ImmutableList.of())) {
assertCassandraQueryFails(
"INSERT INTO " + table.getTableName() + " (id, data) VALUES (1, -2147483649)", // min - 1
"Unable to make int from '-2147483649'");
assertCassandraQueryFails(
"INSERT INTO " + table.getTableName() + " (id, data) VALUES (2, 2147483648)", // max + 1
"Unable to make int from '2147483648'");
}
}

@Test
public void testBigint()
{
Expand All @@ -201,6 +255,22 @@ public void testBigint()
.execute(getQueryRunner(), trinoCreateAndInsert("test_bigint"));
}

@Test
public void testUnsupportedBigint()
{
try (TestCassandraTable table = testTable(
"test_unsupported_bigint",
ImmutableList.of(partitionColumn("id", "bigint"), generalColumn("data", "bigint")),
ImmutableList.of())) {
assertCassandraQueryFails(
"INSERT INTO " + table.getTableName() + " (id, data) VALUES (1, -9223372036854775809)", // min - 1
"Unable to make long from '-9223372036854775809'");
assertCassandraQueryFails(
"INSERT INTO " + table.getTableName() + " (id, data) VALUES (2, 9223372036854775808)", // max + 1
"Unable to make long from '9223372036854775808'");
}
}

@Test
public void testReal()
{
Expand Down Expand Up @@ -558,6 +628,16 @@ private DataSetup cassandraCreateAndInsert(String tableNamePrefix)
return new CassandraCreateAndInsertDataSetup(session::execute, tableNamePrefix, server);
}

private TestCassandraTable testTable(String namePrefix, List<ColumnDefinition> columnDefinitions, List<String> rowsToInsert)
{
return new TestCassandraTable(session::execute, server, "tpch", namePrefix, columnDefinitions, rowsToInsert);
}

private void assertCassandraQueryFails(@Language("SQL") String sql, String expectedMessage)
Comment thread
tangjiangling marked this conversation as resolved.
Outdated
{
assertThatThrownBy(() -> session.execute(sql)).hasMessageContaining(expectedMessage);
}

private static BiFunction<LocalDateTime, ZoneId, String> cassandraTimestampInputLiteralFactory()
{
return timestampInputLiteralFactory(Optional.empty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ public void testUnsupportedTinyint()
{
try (TestTable table = new TestTable(mySqlServer::execute, "tpch.test_unsupported_tinyint", "(data tinyint)")) {
assertMySqlQueryFails(
format("INSERT INTO %s VALUES (-129)", table.getName()), // min - 1
"INSERT INTO " + table.getName() + " VALUES (-129)", // min - 1
"Data truncation: Out of range value for column 'data' at row 1");
assertMySqlQueryFails(
format("INSERT INTO %s VALUES (128)", table.getName()), // max + 1
"INSERT INTO " + table.getName() + " VALUES (128)", // max + 1
"Data truncation: Out of range value for column 'data' at row 1");
}
}
Expand All @@ -171,7 +171,7 @@ public void testUnsupportedSmallint()
{
try (TestTable table = new TestTable(mySqlServer::execute, "tpch.test_unsupported_smallint", "(data smallint)")) {
assertMySqlQueryFails(
format("INSERT INTO %s VALUES (-32769)", table.getName()), // min - 1
"INSERT INTO " + table.getName() + " VALUES (-32769)", // min - 1
"Data truncation: Out of range value for column 'data' at row 1");
assertMySqlQueryFails(
format("INSERT INTO %s VALUES (32768)", table.getName()), // max + 1
Expand All @@ -197,10 +197,10 @@ public void testUnsupportedInteger()
{
try (TestTable table = new TestTable(mySqlServer::execute, "tpch.test_unsupported_integer", "(data integer)")) {
assertMySqlQueryFails(
format("INSERT INTO %s VALUES (-2147483649)", table.getName()), // min - 1
"INSERT INTO " + table.getName() + " VALUES (-2147483649)", // min - 1
"Data truncation: Out of range value for column 'data' at row 1");
assertMySqlQueryFails(
format("INSERT INTO %s VALUES (2147483648)", table.getName()), // max + 1
"INSERT INTO " + table.getName() + " VALUES (2147483648)", // max + 1
"Data truncation: Out of range value for column 'data' at row 1");
}
}
Expand All @@ -223,10 +223,10 @@ public void testUnsupportedBigint()
{
try (TestTable table = new TestTable(mySqlServer::execute, "tpch.test_unsupported_bigint", "(data bigint)")) {
assertMySqlQueryFails(
format("INSERT INTO %s VALUES (-9223372036854775809)", table.getName()), // min - 1
"INSERT INTO " + table.getName() + " VALUES (-9223372036854775809)", // min - 1
"Data truncation: Out of range value for column 'data' at row 1");
assertMySqlQueryFails(
format("INSERT INTO %s VALUES (9223372036854775808)", table.getName()), // max + 1
"INSERT INTO " + table.getName() + " VALUES (9223372036854775808)", // max + 1
"Data truncation: Out of range value for column 'data' at row 1");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ public void testUnsupportedTinyint()
{
try (TestTable table = new TestTable(new PhoenixSqlExecutor(phoenixServer.getJdbcUrl()), "tpch.test_unsupported_tinyint", "(data tinyint, pk tinyint primary key)")) {
assertPhoenixQueryFails(
format("INSERT INTO %s VALUES (-129, 1)", table.getName()), // min - 1
"INSERT INTO " + table.getName() + " VALUES (-129, 1)", // min - 1
"ERROR 203 (22005): Type mismatch. BIGINT and TINYINT for expression: -129 in column 0.DATA");
assertPhoenixQueryFails(
format("INSERT INTO %s VALUES (128, 2)", table.getName()), // max + 1
"INSERT INTO " + table.getName() + " VALUES (128, 2)", // max + 1
"ERROR 203 (22005): Type mismatch. TINYINT and INTEGER for 128");
}
}
Expand Down Expand Up @@ -187,10 +187,10 @@ public void testUnsupportedSmallint()
{
try (TestTable table = new TestTable(new PhoenixSqlExecutor(phoenixServer.getJdbcUrl()), "tpch.test_unsupported_smallint", "(data smallint, pk smallint primary key)")) {
assertPhoenixQueryFails(
format("INSERT INTO %s VALUES (-32769, 1)", table.getName()), // min - 1
"INSERT INTO " + table.getName() + " VALUES (-32769, 1)", // min - 1
"ERROR 203 (22005): Type mismatch. BIGINT and SMALLINT for expression: -32769 in column 0.DATA");
assertPhoenixQueryFails(
format("INSERT INTO %s VALUES (32768, 2)", table.getName()), // max + 1
"INSERT INTO " + table.getName() + " VALUES (32768, 2)", // max + 1
"ERROR 203 (22005): Type mismatch. SMALLINT and INTEGER for 32768");
}
}
Expand Down Expand Up @@ -226,10 +226,10 @@ public void testUnsupportedInteger()
{
try (TestTable table = new TestTable(new PhoenixSqlExecutor(phoenixServer.getJdbcUrl()), "tpch.test_unsupported_integer", "(data integer, pk integer primary key)")) {
assertPhoenixQueryFails(
format("INSERT INTO %s VALUES (-2147483649, 1)", table.getName()), // min - 1
"INSERT INTO " + table.getName() + " VALUES (-2147483649, 1)", // min - 1
"ERROR 203 (22005): Type mismatch. BIGINT and INTEGER for expression: -2147483649 in column 0.DATA");
assertPhoenixQueryFails(
format("INSERT INTO %s VALUES (2147483648, 2)", table.getName()), // max + 1
"INSERT INTO " + table.getName() + " VALUES (2147483648, 2)", // max + 1
"ERROR 203 (22005): Type mismatch. INTEGER and BIGINT for 2147483648");
}
}
Expand Down Expand Up @@ -265,7 +265,7 @@ public void testUnsupportedBigInt()
{
try (TestTable table = new TestTable(new PhoenixSqlExecutor(phoenixServer.getJdbcUrl()), "tpch.test_unsupported_bigint", "(data bigint, pk bigint primary key)")) {
assertPhoenixQueryFails(
format("INSERT INTO %s VALUES (-9223372036854775809, 1)", table.getName()), // min - 1
"INSERT INTO " + table.getName() + " VALUES (-9223372036854775809, 1)", // min - 1
"ERROR 203 (22005): Type mismatch. DECIMAL and BIGINT for expression: -9223372036854775809 in column 0.DATA");

// Phoenix JDBC driver throws ArithmeticException instead of SQLException when the value is larger than max of bigint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ public void testUnsupportedTinyint()
{
try (TestTable table = new TestTable(new PhoenixSqlExecutor(phoenixServer.getJdbcUrl()), "tpch.test_unsupported_tinyint", "(data tinyint, pk tinyint primary key)")) {
assertPhoenixQueryFails(
format("INSERT INTO %s VALUES (-129, 1)", table.getName()), // min - 1
"INSERT INTO " + table.getName() + " VALUES (-129, 1)", // min - 1
"ERROR 203 (22005): Type mismatch. BIGINT and TINYINT for expression: -129 in column 0.DATA");
assertPhoenixQueryFails(
format("INSERT INTO %s VALUES (128, 2)", table.getName()), // max + 1
"INSERT INTO " + table.getName() + " VALUES (128, 2)", // max + 1
"ERROR 203 (22005): Type mismatch. TINYINT and INTEGER for 128");
}
}
Expand Down Expand Up @@ -187,10 +187,10 @@ public void testUnsupportedSmallint()
{
try (TestTable table = new TestTable(new PhoenixSqlExecutor(phoenixServer.getJdbcUrl()), "tpch.test_unsupported_smallint", "(data smallint, pk smallint primary key)")) {
assertPhoenixQueryFails(
format("INSERT INTO %s VALUES (-32769, 1)", table.getName()), // min - 1
"INSERT INTO " + table.getName() + " VALUES (-32769, 1)", // min - 1
"ERROR 203 (22005): Type mismatch. BIGINT and SMALLINT for expression: -32769 in column 0.DATA");
assertPhoenixQueryFails(
format("INSERT INTO %s VALUES (32768, 2)", table.getName()), // max + 1
"INSERT INTO " + table.getName() + " VALUES (32768, 2)", // max + 1
"ERROR 203 (22005): Type mismatch. SMALLINT and INTEGER for 32768");
}
}
Expand Down Expand Up @@ -226,10 +226,10 @@ public void testUnsupportedInteger()
{
try (TestTable table = new TestTable(new PhoenixSqlExecutor(phoenixServer.getJdbcUrl()), "tpch.test_unsupported_integer", "(data integer, pk integer primary key)")) {
assertPhoenixQueryFails(
format("INSERT INTO %s VALUES (-2147483649, 1)", table.getName()), // min - 1
"INSERT INTO " + table.getName() + " VALUES (-2147483649, 1)", // min - 1
"ERROR 203 (22005): Type mismatch. BIGINT and INTEGER for expression: -2147483649 in column 0.DATA");
assertPhoenixQueryFails(
format("INSERT INTO %s VALUES (2147483648, 2)", table.getName()), // max + 1
"INSERT INTO " + table.getName() + " VALUES (2147483648, 2)", // max + 1
"ERROR 203 (22005): Type mismatch. INTEGER and BIGINT for 2147483648");
}
}
Expand Down Expand Up @@ -265,7 +265,7 @@ public void testUnsupportedBigInt()
{
try (TestTable table = new TestTable(new PhoenixSqlExecutor(phoenixServer.getJdbcUrl()), "tpch.test_unsupported_bigint", "(data bigint, pk bigint primary key)")) {
assertPhoenixQueryFails(
format("INSERT INTO %s VALUES (-9223372036854775809, 1)", table.getName()), // min - 1
"INSERT INTO " + table.getName() + " VALUES (-9223372036854775809, 1)", // min - 1
"ERROR 203 (22005): Type mismatch. DECIMAL and BIGINT for expression: -9223372036854775809 in column 0.DATA");

// Phoenix JDBC driver throws ArithmeticException instead of SQLException when the value is larger than max of bigint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ public void testUnsupportedSmallint()
{
try (TestTable table = new TestTable(postgreSqlServer::execute, "tpch.test_unsupported_smallint", "(data smallint)")) {
assertPostgreSqlQueryFails(
format("INSERT INTO %s VALUES (-32769)", table.getName()), // min - 1
"INSERT INTO " + table.getName() + " VALUES (-32769)", // min - 1
"ERROR: smallint out of range");
assertPostgreSqlQueryFails(
format("INSERT INTO %s VALUES (32768)", table.getName()), // max + 1
"INSERT INTO " + table.getName() + " VALUES (32768)", // max + 1
"ERROR: smallint out of range");
}
}
Expand Down Expand Up @@ -260,10 +260,10 @@ public void testUnsupportedInteger()
{
try (TestTable table = new TestTable(postgreSqlServer::execute, "tpch.test_unsupported_integer", "(data integer)")) {
assertPostgreSqlQueryFails(
format("INSERT INTO %s VALUES (-2147483649)", table.getName()), // min - 1
"INSERT INTO " + table.getName() + " VALUES (-2147483649)", // min - 1
"ERROR: integer out of range");
assertPostgreSqlQueryFails(
format("INSERT INTO %s VALUES (2147483648)", table.getName()), // max + 1
"INSERT INTO " + table.getName() + " VALUES (2147483648)", // max + 1
"ERROR: integer out of range");
}
}
Expand Down Expand Up @@ -298,10 +298,10 @@ public void testUnsupportedBigint()
{
try (TestTable table = new TestTable(postgreSqlServer::execute, "tpch.test_unsupported_bigint", "(data bigint)")) {
assertPostgreSqlQueryFails(
format("INSERT INTO %s VALUES (-9223372036854775809)", table.getName()), // min - 1
"INSERT INTO " + table.getName() + " VALUES (-9223372036854775809)", // min - 1
"ERROR: bigint out of range");
assertPostgreSqlQueryFails(
format("INSERT INTO %s VALUES (9223372036854775808)", table.getName()), // max + 1
"INSERT INTO " + table.getName() + " VALUES (9223372036854775808)", // max + 1
"ERROR: bigint out of range");
}
}
Expand Down
Loading