!1336 INSERT OVERWRITE not supported on partitioned cubes
Merge pull request !1336 from sundarannamalai/cube-123021
This commit is contained in:
commit
d5dbb7a6b1
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue