fix syntax error for CreateTableLikeStmt with partition properties (#34187)

fix syntax error for CreateTableLikeStmt with partition properties
This commit is contained in:
Xujian Duan
2024-04-29 11:03:42 +08:00
committed by yiguolei
parent 8ee7bc430d
commit f90c2f6401
3 changed files with 58 additions and 2 deletions

View File

@ -28,6 +28,7 @@ import org.apache.doris.analysis.SlotRef;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.DdlException;
import org.apache.doris.common.util.ListUtil;
import org.apache.doris.common.util.PropertyAnalyzer;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
@ -249,7 +250,7 @@ public class ListPartitionInfo extends PartitionInfo {
Optional.ofNullable(this.idToStoragePolicy.get(entry.getKey())).ifPresent(p -> {
if (!p.equals("")) {
sb.append("PROPERTIES (\"STORAGE POLICY\" = \"");
sb.append(" (\"" + PropertyAnalyzer.PROPERTIES_STORAGE_POLICY + "\" = \"");
sb.append(p).append("\")");
}
});

View File

@ -25,6 +25,7 @@ import org.apache.doris.analysis.RangePartitionDesc;
import org.apache.doris.analysis.SinglePartitionDesc;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.DdlException;
import org.apache.doris.common.util.PropertyAnalyzer;
import org.apache.doris.common.util.RangeUtils;
import com.google.common.base.Preconditions;
@ -299,7 +300,7 @@ public class RangePartitionInfo extends PartitionInfo {
Optional.ofNullable(this.idToStoragePolicy.get(entry.getKey())).ifPresent(p -> {
if (!p.equals("")) {
sb.append("PROPERTIES (\"STORAGE POLICY\" = \"");
sb.append(" (\"" + PropertyAnalyzer.PROPERTIES_STORAGE_POLICY + "\" = \"");
sb.append(p).append("\")");
}
});

View File

@ -47,4 +47,58 @@ suite("test_create_table_like") {
VALUES ("test1", 1, 123456789, 1234567891, 123456789, 1234567891, 123456789)"""
qt_select_table_like """select * from decimal_test_like"""
def resource_name = "test_create_table_like_use_resource"
def policy_name = "test_create_table_like_use_policy"
def table1 = "create_table_partion_use_created_policy"
def table2 = "create_table_partion_like_use_created_policy"
sql """
CREATE RESOURCE IF NOT EXISTS $resource_name
PROPERTIES(
"type"="s3",
"AWS_REGION" = "bj",
"AWS_ENDPOINT" = "bj.s3.comaaaa",
"AWS_ROOT_PATH" = "path/to/rootaaaa",
"AWS_SECRET_KEY" = "aaaa",
"AWS_ACCESS_KEY" = "bbba",
"AWS_BUCKET" = "test-bucket",
"s3_validity_check" = "false"
);
"""
sql """
CREATE STORAGE POLICY IF NOT EXISTS $policy_name
PROPERTIES(
"storage_resource" = "$resource_name",
"cooldown_ttl" = "10"
);
"""
sql """DROP TABLE IF EXISTS $table1"""
sql """DROP TABLE IF EXISTS $table2"""
sql """
CREATE TABLE $table1
(
k1 DATE,
k2 INT,
V1 VARCHAR(2048) REPLACE
) PARTITION BY RANGE (k1) (
PARTITION p1 VALUES LESS THAN ("2022-01-01") ("storage_policy" = "$policy_name"),
PARTITION p2 VALUES LESS THAN ("2022-02-01") ("storage_policy" = "$policy_name")
)
DISTRIBUTED BY HASH(k2) BUCKETS 1
PROPERTIES (
"replication_num"="1"
);
"""
sql """
CREATE TABLE $table2 LIKE $table1
"""
sql """DROP TABLE IF EXISTS $table1"""
sql """DROP TABLE IF EXISTS $table2"""
sql """DROP STORAGE POLICY $policy_name"""
sql """DROP RESOURCE $resource_name"""
}