use of io.trino.testing.sql.TrinoSqlExecutor in project trino by trinodb.
the class TestKuduIntegrationDecimalColumns method testDeleteByPrimaryKeyDecimalColumn.
@Test
public void testDeleteByPrimaryKeyDecimalColumn() {
try (TestTable testTable = new TestTable(new TrinoSqlExecutor(getQueryRunner()), "test_decimal", "(decimal_id decimal(18, 3) WITH (primary_key=true), col_decimal decimal(18, 3)) " + "WITH (partition_by_hash_columns = ARRAY['decimal_id'], partition_by_hash_buckets = 2)")) {
assertUpdate(format("INSERT INTO %s VALUES (1.1, 1.1), (2.2, 2.2)", testTable.getName()), 2);
assertUpdate(format("DELETE FROM %s WHERE decimal_id = 2.2", testTable.getName()), 1);
assertQuery(format("SELECT * FROM %s", testTable.getName()), "VALUES (1.1, 1.1)");
}
}
use of io.trino.testing.sql.TrinoSqlExecutor in project trino by trinodb.
the class BaseHiveConnectorTest method testRequiredPartitionFilterAppliedOnDifferentSchema.
@Test
public void testRequiredPartitionFilterAppliedOnDifferentSchema() {
String schemaName = "schema_" + randomTableSuffix();
Session session = Session.builder(getSession()).setIdentity(Identity.forUser("hive").withRole("hive", new SelectedRole(ROLE, Optional.of("admin"))).build()).setCatalogSessionProperty("hive", "query_partition_filter_required", "true").setCatalogSessionProperty("hive", "query_partition_filter_required_schemas", format("[\"%s\"]", schemaName)).build();
getQueryRunner().execute("CREATE SCHEMA " + schemaName);
try (TestTable table = new TestTable(new TrinoSqlExecutor(getQueryRunner(), session), "test_required_partition_filter_", "(id integer, a varchar, b varchar) WITH (partitioned_by = ARRAY['b'])", ImmutableList.of("1, '1', 'b'"))) {
// no partition filter
assertQuery(session, format("SELECT id FROM %s WHERE a = '1'", table.getName()), "SELECT 1");
computeActual(session, format("EXPLAIN SELECT id FROM %s WHERE a = '1'", table.getName()));
computeActual(session, format("EXPLAIN ANALYZE SELECT id FROM %s WHERE a = '1'", table.getName()));
// partition filter that gets removed by planner
assertQuery(session, format("SELECT id FROM %s WHERE b IS NOT NULL OR true", table.getName()), "SELECT 1");
// Join on non-partition column
assertUpdate(session, format("CREATE TABLE %s.%s_right (id integer, a varchar, b varchar, ds varchar) WITH (partitioned_by = ARRAY['ds'])", schemaName, table.getName()));
assertUpdate(session, format("INSERT INTO %s.%s_right (id, a, ds) VALUES (1, 'a', '1')", schemaName, table.getName()), 1);
assertQueryFails(session, format("SELECT count(*) FROM %2$s l JOIN %s.%2$s_right r ON l.id = r.id WHERE r.a = 'a'", schemaName, table.getName()), format("Filter required on %s\\.%s_right for at least one partition column: ds", schemaName, table.getName()));
assertQuery(session, format("SELECT count(*) FROM %2$s l JOIN %s.%2$s_right r ON l.id = r.id WHERE r.ds = '1'", schemaName, table.getName()), "SELECT 1");
assertUpdate(session, format("DROP TABLE %s.%s_right", schemaName, table.getName()));
}
getQueryRunner().execute("DROP SCHEMA " + schemaName);
}
use of io.trino.testing.sql.TrinoSqlExecutor in project trino by trinodb.
the class TestKuduIntegrationDecimalColumns method doTestCreateTableWithDecimalColumn.
private void doTestCreateTableWithDecimalColumn(TestDecimal decimal) {
String tableDefinition = format("(id INT WITH (primary_key=true), dec DECIMAL(%s, %s)) " + "WITH (partition_by_hash_columns = ARRAY['id'], partition_by_hash_buckets = 2)", decimal.precision, decimal.scale);
try (TestTable testTable = new TestTable(new TrinoSqlExecutor(getQueryRunner()), decimal.getTableName(), tableDefinition)) {
String fullPrecisionValue = "1234567890.1234567890123456789012345678";
int maxScale = decimal.precision - 10;
int valuePrecision = decimal.precision - maxScale + Math.min(maxScale, decimal.scale);
String insertValue = fullPrecisionValue.substring(0, valuePrecision + 1);
assertUpdate(format("INSERT INTO %s VALUES(1, DECIMAL '%s')", testTable.getName(), insertValue), 1);
MaterializedResult result = computeActual(format("SELECT id, CAST((dec - (DECIMAL '%s')) as DOUBLE) FROM %s", insertValue, testTable.getName()));
assertEquals(result.getRowCount(), 1);
Object obj = result.getMaterializedRows().get(0).getField(1);
assertTrue(obj instanceof Double);
Double actual = (Double) obj;
assertEquals(0, actual, 0.3 * Math.pow(0.1, decimal.scale), "p=" + decimal.precision + ",s=" + decimal.scale + " => " + actual + ",insert = " + insertValue);
}
}
use of io.trino.testing.sql.TrinoSqlExecutor in project trino by trinodb.
the class TestKuduIntegrationDecimalColumns method testDecimalColumn.
@Test
public void testDecimalColumn() {
try (TestTable testTable = new TestTable(new TrinoSqlExecutor(getQueryRunner()), "test_decimal", "(id INT WITH (primary_key=true), col_decimal decimal(10, 6)) " + "WITH (partition_by_hash_columns = ARRAY['id'], partition_by_hash_buckets = 2)")) {
assertUpdate(format("INSERT INTO %s VALUES (0, 0.0), (2, 2.2), (1, 1.1)", testTable.getName()), 3);
assertQuery(format("SELECT * FROM %s WHERE col_decimal = 1.1", testTable.getName()), "VALUES (1, 1.1)");
assertUpdate(format("DELETE FROM %s WHERE col_decimal = 1.1", testTable.getName()), 1);
assertQueryReturnsEmptyResult(format("SELECT * FROM %s WHERE col_decimal = 1.1", testTable.getName()));
}
}
Aggregations