Skip to content

Commit

Permalink
[BugFix] fix create table like fail in cloud native pk table (StarRoc…
Browse files Browse the repository at this point in the history
…ks#30198)

Signed-off-by: luohaha <18810541851@163.com>
  • Loading branch information
luohaha authored Aug 31, 2023
1 parent 7279d36 commit c277566
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import com.starrocks.sql.analyzer.SemanticException;
import com.starrocks.sql.ast.Property;
import com.starrocks.thrift.TCompressionType;
import com.starrocks.thrift.TPersistentIndexType;
import com.starrocks.thrift.TStorageMedium;
import com.starrocks.thrift.TStorageType;
import com.starrocks.thrift.TTabletType;
Expand Down Expand Up @@ -1020,6 +1021,19 @@ public static PeriodDuration analyzeDataCachePartitionDuration(Map<String, Strin
return TimeUtils.parseHumanReadablePeriodOrDuration(text);
}

public static TPersistentIndexType analyzePersistentIndexType(Map<String, String> properties) throws AnalysisException {
if (properties != null && properties.containsKey(PROPERTIES_PERSISTENT_INDEX_TYPE)) {
String type = properties.get(PROPERTIES_PERSISTENT_INDEX_TYPE);
properties.remove(PROPERTIES_PERSISTENT_INDEX_TYPE);
if (type.equalsIgnoreCase("LOCAL")) {
return TPersistentIndexType.LOCAL;
} else {
throw new AnalysisException("Invalid persistent index type: " + type);
}
}
return TPersistentIndexType.LOCAL;
}

public static PeriodDuration analyzeStorageCoolDownTTL(Map<String, String> properties,
boolean removeProperties) throws AnalysisException {
String text = properties.get(PROPERTIES_STORAGE_COOLDOWN_TTL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import com.starrocks.sql.ast.RangePartitionDesc;
import com.starrocks.sql.ast.SingleRangePartitionDesc;
import com.starrocks.thrift.TCompressionType;
import com.starrocks.thrift.TPersistentIndexType;
import com.starrocks.thrift.TStorageType;
import com.starrocks.thrift.TTabletType;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -310,7 +309,11 @@ public Table createTable(LocalMetastore metastore, Database db, CreateTableStmt
table.setEnablePersistentIndex(false);
}
} else {
table.setPersistentIndexType(TPersistentIndexType.LOCAL);
try {
table.setPersistentIndexType(PropertyAnalyzer.analyzePersistentIndexType(properties));
} catch (AnalysisException e) {
throw new DdlException(e.getMessage());
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.starrocks.common.util.TimeUtils;
import com.starrocks.qe.ConnectContext;
import com.starrocks.thrift.TCompressionType;
import com.starrocks.thrift.TPersistentIndexType;
import com.starrocks.thrift.TStorageMedium;
import com.starrocks.utframe.UtFrameUtils;
import org.junit.Assert;
Expand Down Expand Up @@ -283,6 +284,29 @@ public void testDefaultTableCompression() throws AnalysisException {
Assert.assertEquals(TCompressionType.ZLIB, (PropertyAnalyzer.analyzeCompressionType(property)));
}

@Test
public void testPersistentIndexType() throws AnalysisException {
// empty property
Map<String, String> property = new HashMap<>();
Assert.assertEquals(TPersistentIndexType.LOCAL, PropertyAnalyzer.analyzePersistentIndexType(property));

Map<String, String> property2 = new HashMap<>();
property2.put(PropertyAnalyzer.PROPERTIES_PERSISTENT_INDEX_TYPE, "LOCAL");
Assert.assertEquals(TPersistentIndexType.LOCAL, PropertyAnalyzer.analyzePersistentIndexType(property2));

Map<String, String> property3 = new HashMap<>();
property3.put(PropertyAnalyzer.PROPERTIES_PERSISTENT_INDEX_TYPE, "local");
Assert.assertEquals(TPersistentIndexType.LOCAL, PropertyAnalyzer.analyzePersistentIndexType(property3));

try {
Map<String, String> property4 = new HashMap<>();
property4.put(PropertyAnalyzer.PROPERTIES_PERSISTENT_INDEX_TYPE, "LOCAL2");
TPersistentIndexType type = PropertyAnalyzer.analyzePersistentIndexType(property4);
} catch (AnalysisException e) {
Assert.assertTrue(e.getMessage().contains("Invalid persistent index type: LOCAL2"));
}
}

@Test
public void testSchemaChangeProperties() throws AnalysisException {
Map<String, String> props = new HashMap<>();
Expand Down

0 comments on commit c277566

Please sign in to comment.