You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ja...@apache.org on 2020/10/20 20:16:45 UTC
[incubator-pinot] branch master updated: Add more validation for
upsert config (#6153)
This is an automated email from the ASF dual-hosted git repository.
jackie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git
The following commit(s) were added to refs/heads/master by this push:
new da451a8 Add more validation for upsert config (#6153)
da451a8 is described below
commit da451a8f3dbfcfe18d344e8b3b40c69e6ef08325
Author: Yupeng Fu <yu...@users.noreply.github.com>
AuthorDate: Tue Oct 20 13:16:24 2020 -0700
Add more validation for upsert config (#6153)
Part of a series of PRs for #4261
- validate primary key columns
- validate startree index not in use
---
.../java/org/apache/pinot/core/util/SchemaUtils.java | 8 ++++++++
.../org/apache/pinot/core/util/TableConfigUtils.java | 4 ++++
.../org/apache/pinot/core/util/SchemaUtilsTest.java | 18 ++++++++++++++++++
.../apache/pinot/core/util/TableConfigUtilsTest.java | 13 +++++++++++++
4 files changed, 43 insertions(+)
diff --git a/pinot-core/src/main/java/org/apache/pinot/core/util/SchemaUtils.java b/pinot-core/src/main/java/org/apache/pinot/core/util/SchemaUtils.java
index 20bb089..6462dbd 100644
--- a/pinot-core/src/main/java/org/apache/pinot/core/util/SchemaUtils.java
+++ b/pinot-core/src/main/java/org/apache/pinot/core/util/SchemaUtils.java
@@ -75,9 +75,11 @@ public class SchemaUtils {
Set<String> transformedColumns = new HashSet<>();
Set<String> argumentColumns = new HashSet<>();
+ Set<String> primaryKeyColumnCandidates = new HashSet<>();
for (FieldSpec fieldSpec : schema.getAllFieldSpecs()) {
if (!fieldSpec.isVirtualColumn()) {
String column = fieldSpec.getName();
+ primaryKeyColumnCandidates.add(column);
String transformFunction = fieldSpec.getTransformFunction();
if (transformFunction != null) {
try {
@@ -104,6 +106,12 @@ public class SchemaUtils {
Preconditions.checkState(Collections.disjoint(transformedColumns, argumentColumns),
"Columns: %s are a result of transformations, and cannot be used as arguments to other transform functions",
transformedColumns.retainAll(argumentColumns));
+ if (schema.getPrimaryKeyColumns() != null) {
+ for (String primaryKeyColumn : schema.getPrimaryKeyColumns()) {
+ Preconditions.checkState(primaryKeyColumnCandidates.contains(primaryKeyColumn),
+ "The primary key column must exist");
+ }
+ }
}
/**
diff --git a/pinot-core/src/main/java/org/apache/pinot/core/util/TableConfigUtils.java b/pinot-core/src/main/java/org/apache/pinot/core/util/TableConfigUtils.java
index 7d76ea9..d1020d5 100644
--- a/pinot-core/src/main/java/org/apache/pinot/core/util/TableConfigUtils.java
+++ b/pinot-core/src/main/java/org/apache/pinot/core/util/TableConfigUtils.java
@@ -265,6 +265,10 @@ public final class TableConfigUtils {
tableConfig.getRoutingConfig() != null && RoutingConfig.REPLICA_GROUP_INSTANCE_SELECTOR_TYPE
.equalsIgnoreCase(tableConfig.getRoutingConfig().getInstanceSelectorType()),
"Upsert table must use replica-group (i.e. replicaGroup) based routing");
+ // no startree index
+ Preconditions.checkState(
+ CollectionUtils.isEmpty(tableConfig.getIndexingConfig().getStarTreeIndexConfigs()) && !tableConfig
+ .getIndexingConfig().isEnableDefaultStarTree(), "The upsert table cannot have star-tree index.");
}
/**
diff --git a/pinot-core/src/test/java/org/apache/pinot/core/util/SchemaUtilsTest.java b/pinot-core/src/test/java/org/apache/pinot/core/util/SchemaUtilsTest.java
index 4767e87..ef3aa90 100644
--- a/pinot-core/src/test/java/org/apache/pinot/core/util/SchemaUtilsTest.java
+++ b/pinot-core/src/test/java/org/apache/pinot/core/util/SchemaUtilsTest.java
@@ -222,6 +222,24 @@ public class SchemaUtilsTest {
}
@Test
+ public void testValidatePrimaryKeyColumns() {
+ Schema pinotSchema;
+ // non-existing column used as primary key
+ pinotSchema = new Schema.SchemaBuilder()
+ .addTime(new TimeGranularitySpec(DataType.LONG, TimeUnit.MILLISECONDS, "incoming"),
+ new TimeGranularitySpec(DataType.INT, TimeUnit.DAYS, "outgoing")).addSingleValueDimension("col", DataType.INT)
+ .setPrimaryKeyColumns(Lists.newArrayList("test")).build();
+ checkValidationFails(pinotSchema);
+
+ // valid primary key
+ pinotSchema = new Schema.SchemaBuilder()
+ .addTime(new TimeGranularitySpec(DataType.LONG, TimeUnit.MILLISECONDS, "incoming"),
+ new TimeGranularitySpec(DataType.INT, TimeUnit.DAYS, "outgoing")).addSingleValueDimension("col", DataType.INT)
+ .setPrimaryKeyColumns(Lists.newArrayList("col")).build();
+ SchemaUtils.validate(pinotSchema);
+ }
+
+ @Test
public void testGroovyFunctionSyntax() {
Schema pinotSchema;
// incorrect groovy function syntax
diff --git a/pinot-core/src/test/java/org/apache/pinot/core/util/TableConfigUtilsTest.java b/pinot-core/src/test/java/org/apache/pinot/core/util/TableConfigUtilsTest.java
index b48ba8e..55aa1d6 100644
--- a/pinot-core/src/test/java/org/apache/pinot/core/util/TableConfigUtilsTest.java
+++ b/pinot-core/src/test/java/org/apache/pinot/core/util/TableConfigUtilsTest.java
@@ -25,7 +25,9 @@ import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
+import org.apache.pinot.common.function.AggregationFunctionType;
import org.apache.pinot.common.tier.TierFactory;
+import org.apache.pinot.core.startree.v2.AggregationFunctionColumnPair;
import org.apache.pinot.spi.config.table.ColumnPartitionConfig;
import org.apache.pinot.spi.config.table.FieldConfig;
import org.apache.pinot.spi.config.table.IngestionConfig;
@@ -720,5 +722,16 @@ public class TableConfigUtilsTest {
} catch (Exception e) {
Assert.fail("Should not fail upsert validation");
}
+ StarTreeIndexConfig starTreeIndexConfig = new StarTreeIndexConfig(Lists.newArrayList("myCol"), null, Collections
+ .singletonList(new AggregationFunctionColumnPair(AggregationFunctionType.COUNT, "myCol").toColumnName()), 10);
+ tableConfig = new TableConfigBuilder(TableType.REALTIME).setTableName(TABLE_NAME)
+ .setUpsertConfig(new UpsertConfig(UpsertConfig.Mode.FULL))
+ .setRoutingConfig(new RoutingConfig(null, null, "replicaGroup"))
+ .setStarTreeIndexConfigs(Lists.newArrayList(starTreeIndexConfig)).setStreamConfigs(streamConfigs).build();
+ try {
+ TableConfigUtils.validateUpsertConfig(tableConfig, schema);
+ } catch (Exception e) {
+ Assert.assertEquals(e.getMessage(), "The upsert table cannot have star-tree index.");
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org