diff --git a/hetu-docs/en/preagg/statements.md b/hetu-docs/en/preagg/statements.md index e071dd7ea..13bdec14d 100644 --- a/hetu-docs/en/preagg/statements.md +++ b/hetu-docs/en/preagg/statements.md @@ -117,8 +117,10 @@ INSERT OVERWRITE CUBE cube_name [WHERE condition] ``` ### Description -Similar to INSERT INTO CUBE statement but with this statement the existing data is overwritten. Predicates -are optional. +Similar to `INSERT INTO CUBE` statement but with this statement the existing data is overwritten. Predicates +are optional.`INSERT OVERWRITE CUBE` is not supported on partitioned cubes. Cubes are essentially stored as tables and so `INSERT OVERWRITE` only +replaces the matching partitions and does not overwrite the entire table. So this operation is blocked on partitioned cube. +Drop and recreate cube if needed. ### Examples Insert data based on condition into the `orders_cube` Cube: diff --git a/hetu-docs/zh/preagg/statements.md b/hetu-docs/zh/preagg/statements.md index 96c134741..b6752fabc 100644 --- a/hetu-docs/zh/preagg/statements.md +++ b/hetu-docs/zh/preagg/statements.md @@ -117,8 +117,9 @@ INSERT OVERWRITE CUBE cube_name [WHERE condition] ``` ### 描述 -类似于INSERT INTO CUBE语句,但使用此语句覆盖现有数据。 -谓词是可选的。 +类似于"INSERT INTO CUBE"语句,但使用此语句覆盖现有数据。谓词是可选的。分区的Cubes不支持`INSERT OVERWRITE CUBE`类语句。 +Cubes本质上存储为表,因此只有`INSERT OVERWRITE`替换匹配的分区并且不会覆盖整个表。所以这个操作在分区的Cube上被阻止。 +删除并重新创建多维数据集,如果 需要。 ### 例子 根据条件插入数据到`orders_cube`Cube: diff --git a/presto-cli/src/main/java/io/prestosql/cli/CubeConsole.java b/presto-cli/src/main/java/io/prestosql/cli/CubeConsole.java index e98e57de4..3e86728ff 100644 --- a/presto-cli/src/main/java/io/prestosql/cli/CubeConsole.java +++ b/presto-cli/src/main/java/io/prestosql/cli/CubeConsole.java @@ -624,9 +624,7 @@ public class CubeConsole else { //if the range is within the processing size limit then we run a single insert query only String queryInsert = String.format(INSERT_INTO_CUBE_STRING, cubeName, whereClause); - if (!console.runQuery(queryRunner, queryInsert, outputFormat, schemaChanged, usePager, showProgress, terminal, out, errorChannel)) { - return false; - } + return console.runQuery(queryRunner, queryInsert, outputFormat, schemaChanged, usePager, showProgress, terminal, out, errorChannel); } return true; } diff --git a/presto-main/src/main/java/io/prestosql/sql/analyzer/StatementAnalyzer.java b/presto-main/src/main/java/io/prestosql/sql/analyzer/StatementAnalyzer.java index 3a59b3a73..2febec7c5 100644 --- a/presto-main/src/main/java/io/prestosql/sql/analyzer/StatementAnalyzer.java +++ b/presto-main/src/main/java/io/prestosql/sql/analyzer/StatementAnalyzer.java @@ -538,6 +538,12 @@ class StatementAnalyzer throw new SemanticException(MISSING_CUBE, insertCube, "Cube '%s' table handle does not exist", targetCube); } + TableMetadata cubeTableMetadata = metadata.getTableMetadata(session, targetCubeHandle.get()); + boolean isPartitioned = cubeTableMetadata.getMetadata().getProperties().containsKey("partitioned_by"); + if (insertCube.isOverwrite() && isPartitioned) { + throw new PrestoException(StandardErrorCode.NOT_SUPPORTED, "INSERT OVERWRITE not supported on partitioned cube. Drop and recreate cube, if needed."); + } + QualifiedObjectName tableName = QualifiedObjectName.valueOf(cubeMetadata.getSourceTableName()); TableHandle sourceTableHandle = metadata.getTableHandle(session, tableName) .orElseThrow(() -> new SemanticException(MISSING_TABLE, insertCube, "Source table '%s' on which cube was built is missing", tableName.toString())); diff --git a/presto-tests/src/main/java/io/prestosql/tests/AbstractTestStarTreeQueries.java b/presto-tests/src/main/java/io/prestosql/tests/AbstractTestStarTreeQueries.java index 06e73c63d..d37038f58 100644 --- a/presto-tests/src/main/java/io/prestosql/tests/AbstractTestStarTreeQueries.java +++ b/presto-tests/src/main/java/io/prestosql/tests/AbstractTestStarTreeQueries.java @@ -375,17 +375,15 @@ public abstract class AbstractTestStarTreeQueries @Test public void testInsertOverwriteCube() { - computeActual("CREATE TABLE nation_table_cube_insert_overwrite_test_1 AS SELECT * FROM nation"); - assertUpdate("CREATE CUBE nation_insert_overwrite_cube_1 ON nation_table_cube_insert_overwrite_test_1 " + - "WITH (AGGREGATIONS=(count(*), COUNT(distinct nationkey), count(distinct regionkey), avg(nationkey), count(regionkey), sum(regionkey)," + - " min(regionkey), max(regionkey), max(nationkey), min(nationkey))," + - " group=(nationkey), format= 'orc', partitioned_by = ARRAY['nationkey'])"); - assertUpdate("INSERT INTO CUBE nation_insert_overwrite_cube_1 where nationkey > 5", 19); - assertEquals(computeScalar("SELECT COUNT(*) FROM nation_insert_overwrite_cube_1"), 19L); - assertUpdate("INSERT OVERWRITE CUBE nation_insert_overwrite_cube_1 where nationkey > 5", 19); - assertEquals(computeScalar("SELECT COUNT(*) FROM nation_insert_overwrite_cube_1"), 19L); - assertUpdate("DROP CUBE nation_insert_overwrite_cube_1"); - assertUpdate("DROP TABLE nation_table_cube_insert_overwrite_test_1"); + computeActual("CREATE TABLE orders_table_overwrite_cube AS SELECT * FROM orders"); + assertQuerySucceeds("CREATE CUBE orders_cube_test_overwrite ON orders_table_overwrite_cube WITH (AGGREGATIONS = (count(*), sum(totalprice), avg(totalprice)), GROUP = (custkey))"); + assertUpdate("INSERT INTO CUBE orders_cube_test_overwrite", 1000L); + assertEquals(computeScalar("SELECT COUNT(*) FROM orders_cube_test_overwrite"), 1000L); + + assertQuerySucceeds("CREATE CUBE orders_partitioned_cube_test_overwrite ON orders_table_overwrite_cube WITH (AGGREGATIONS = (count(*), sum(totalprice), avg(totalprice)), GROUP = (custkey, orderstatus), PARTITIONED_BY = ARRAY['orderstatus'])"); + assertUpdate("INSERT INTO CUBE orders_partitioned_cube_test_overwrite", 2298L); + assertQueryFails("INSERT OVERWRITE CUBE orders_partitioned_cube_test_overwrite WHERE custkey > 200", "INSERT OVERWRITE not supported on partitioned cube. Drop and recreate cube, if needed."); + assertUpdate("DROP TABLE orders_table_overwrite_cube"); } @Test