Jackie-Jiang commented on a change in pull request #8224:
URL: https://github.com/apache/pinot/pull/8224#discussion_r812408932
##########
File path:
pinot-spi/src/main/java/org/apache/pinot/spi/config/table/ColumnPartitionConfig.java
##########
@@ -21,20 +21,29 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
+import java.util.Map;
+import javax.annotation.Nullable;
import org.apache.pinot.spi.config.BaseJsonConfig;
public class ColumnPartitionConfig extends BaseJsonConfig {
private final String _functionName;
private final int _numPartitions;
+ private final Map<String, String> _functionConfig;
+
+ public ColumnPartitionConfig(String functionName, int numPartitions) {
+ this(functionName, numPartitions, null);
+ }
@JsonCreator
public ColumnPartitionConfig(@JsonProperty(value = "functionName", required
= true) String functionName,
- @JsonProperty(value = "numPartitions", required = true) int
numPartitions) {
+ @JsonProperty(value = "numPartitions", required = true) int
numPartitions,
+ @JsonProperty(value = "functionConfig") Map<String, String>
functionConfig) {
Review comment:
(minor)
```suggestion
@JsonProperty(value = "functionConfig") @Nullable Map<String, String>
functionConfig) {
```
##########
File path:
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/partition/PartitionFunction.java
##########
@@ -49,4 +50,8 @@
* @return Number of possible partitions.
*/
int getNumPartitions();
+
+ default Map<String, String> getFunctionConfig() {
Review comment:
```suggestion
@Nullable
default Map<String, String> getFunctionConfig() {
```
##########
File path:
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/creator/StatsCollectorConfig.java
##########
@@ -76,6 +77,10 @@ public int getNumPartitions(String column) {
: SegmentPartitionConfig.INVALID_NUM_PARTITIONS;
}
+ public Map<String, String> getFunctionConfig(String column) {
Review comment:
```suggestion
@Nullable
public Map<String, String> getFunctionConfig(String column) {
```
##########
File path:
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/partition/BoundedColumnValuePartitionFunction.java
##########
@@ -0,0 +1,92 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.spi.partition;
+
+import com.google.common.base.Preconditions;
+import java.util.Map;
+
+
+/**
+ * Implementation of {@link PartitionFunction} which partitions based
configured column values.
+ *
+ * "columnPartitionMap": {
+ * "subject": {
+ * "functionName": "BoundedColumnValue",
+ * "functionConfig": {
+ * "columnValues": "Maths|English|Chemistry"
+ * }
+ * }
+ * }
+ * With this partition config on column "subject", partitionId would be 1 for
Maths, 2 for English and so on.
+ * partitionId would be "0" for all other values which is not configured but
may occur.
+ */
+public class BoundedColumnValuePartitionFunction implements PartitionFunction {
+ private static final int DEFAULT_PARTITION_ID = 0;
+ private static final String NAME = "BoundedColumnValue";
+ private static final String COLUMN_VALUES = "columnValues";
+ private final Map<String, String> _functionConfig;
+ private final String[] _values;
Review comment:
Sounds good, let's keep array then
##########
File path:
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/partition/PartitionFunctionFactory.java
##########
@@ -60,13 +60,15 @@ private PartitionFunctionFactory() {
*
* @param functionName Name of partition function
* @param numPartitions Number of partitions.
+ * @param functionConfig The function configuration for given function.
* @return Partition function
*/
// TODO: introduce a way to inject custom partition function
// a custom partition function could be used in the realtime stream
partitioning or offline segment partitioning.
// The PartitionFunctionFactory should be able to support these default
implementations, as well as instantiate
// based on config
- public static PartitionFunction getPartitionFunction(String functionName,
int numPartitions) {
+ public static PartitionFunction getPartitionFunction(String functionName,
int numPartitions,
+ Map<String, String>
functionConfig) {
Review comment:
Please reformat the file with [Pinot
Style](https://docs.pinot.apache.org/developers/developers-and-contributors/code-setup#intellij)
```suggestion
@Nullable Map<String, String> functionConfig) {
```
##########
File path:
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/partition/metadata/ColumnPartitionMetadata.java
##########
@@ -52,11 +57,14 @@
* @param functionName Name of the partition function
* @param numPartitions Number of total partitions for this column
* @param partitions Set of partitions the column contains
+ * @param functionConfig Configuration required by partition function.
*/
- public ColumnPartitionMetadata(String functionName, int numPartitions,
Set<Integer> partitions) {
+ public ColumnPartitionMetadata(String functionName, int numPartitions,
Set<Integer> partitions,
+ Map<String, String> functionConfig) {
Review comment:
(code format)
```suggestion
@Nullable Map<String, String> functionConfig) {
```
##########
File path:
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/partition/BoundedColumnValuePartitionFunction.java
##########
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.spi.partition;
+
+import com.google.common.base.Preconditions;
+import java.util.Map;
+
+
+/**
+ * Implementation of {@link PartitionFunction} which partitions based
configured column values.
+ *
+ * "columnPartitionMap": {
+ * "subject": {
+ * "functionName": "BoundedColumnValue",
+ * "functionConfig": {
+ * "columnValues": "Maths|English|Chemistry"
+ * }
+ * }
+ * }
+ * With this partition config on column "subject", partitionId would be 1 for
Maths, 2 for English and so on.
+ * partitionId would be "0" for all other values which is not configured but
may occur.
+ */
+public class BoundedColumnValuePartitionFunction implements PartitionFunction {
+ private static final int DEFAULT_PARTITION_ID = 0;
+ private static final String NAME = "BoundedColumnValue";
+ private static final String COLUMN_VALUES = "columnValues";
+ private static final String COLUMN_VALUES_DELIMITER =
"columnValuesDelimiter";
+ private final int _numPartitions;
+ private final Map<String, String> _functionConfig;
+ private final String[] _values;
+
+ public BoundedColumnValuePartitionFunction(int numPartitions, Map<String,
String> functionConfig) {
+ Preconditions.checkArgument(functionConfig != null &&
functionConfig.size() > 0,
+ "'functionConfig' should be present, specified", functionConfig);
+ Preconditions.checkState(functionConfig.get(COLUMN_VALUES) != null,
"columnValues must be configured");
+ Preconditions.checkState(functionConfig.get(COLUMN_VALUES_DELIMITER) !=
null,
+ "'columnValuesDelimiter' must be configured");
+ _functionConfig = functionConfig;
+ _values =
functionConfig.get(COLUMN_VALUES).split(functionConfig.get(COLUMN_VALUES_DELIMITER));
+ Preconditions.checkState(_values.length == numPartitions,
Review comment:
`numPartitions` should be `values.length + 1`
##########
File path:
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/partition/metadata/ColumnPartitionMetadata.java
##########
@@ -52,11 +57,14 @@
* @param functionName Name of the partition function
* @param numPartitions Number of total partitions for this column
* @param partitions Set of partitions the column contains
+ * @param functionConfig Configuration required by partition function.
*/
- public ColumnPartitionMetadata(String functionName, int numPartitions,
Set<Integer> partitions) {
+ public ColumnPartitionMetadata(String functionName, int numPartitions,
Set<Integer> partitions,
+ Map<String, String> functionConfig) {
Review comment:
Either way is fine since `functionConfig` is always passed in
non-testing code
##########
File path:
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/partition/BoundedColumnValuePartitionFunction.java
##########
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.spi.partition;
+
+import com.google.common.base.Preconditions;
+import java.util.Map;
+
+
+/**
+ * Implementation of {@link PartitionFunction} which partitions based
configured column values.
+ *
+ * "columnPartitionMap": {
+ * "subject": {
+ * "functionName": "BoundedColumnValue",
+ * "functionConfig": {
+ * "columnValues": "Maths|English|Chemistry"
+ * }
+ * }
+ * }
+ * With this partition config on column "subject", partitionId would be 1 for
Maths, 2 for English and so on.
+ * partitionId would be "0" for all other values which is not configured but
may occur.
+ */
+public class BoundedColumnValuePartitionFunction implements PartitionFunction {
+ private static final int DEFAULT_PARTITION_ID = 0;
+ private static final String NAME = "BoundedColumnValue";
+ private static final String COLUMN_VALUES = "columnValues";
+ private static final String COLUMN_VALUES_DELIMITER =
"columnValuesDelimiter";
+ private final int _numPartitions;
+ private final Map<String, String> _functionConfig;
+ private final String[] _values;
+
+ public BoundedColumnValuePartitionFunction(int numPartitions, Map<String,
String> functionConfig) {
+ Preconditions.checkArgument(functionConfig != null &&
functionConfig.size() > 0,
+ "'functionConfig' should be present, specified", functionConfig);
+ Preconditions.checkState(functionConfig.get(COLUMN_VALUES) != null,
"columnValues must be configured");
+ Preconditions.checkState(functionConfig.get(COLUMN_VALUES_DELIMITER) !=
null,
+ "'columnValuesDelimiter' must be configured");
+ _functionConfig = functionConfig;
+ _values =
functionConfig.get(COLUMN_VALUES).split(functionConfig.get(COLUMN_VALUES_DELIMITER));
Review comment:
Let's use `StringUtils.split()` to avoid regex matching. This way we
don't need to escape special characters in delimiter, and also get better
performance.
##########
File path:
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/metadata/ColumnMetadataImpl.java
##########
@@ -279,8 +284,26 @@ public static ColumnMetadataImpl
fromPropertiesConfiguration(String column, Prop
String partitionFunctionName = config.getString(Column.getKeyFor(column,
Column.PARTITION_FUNCTION), null);
if (partitionFunctionName != null) {
int numPartitions = config.getInt(Column.getKeyFor(column,
Column.NUM_PARTITIONS));
+ Map<String, String> partitionFunctionConfigMap = null;
+ Configuration partitionFunctionConfig =
config.subset(Column.getKeyFor(column, Column.PARTITION_FUNCTION_CONFIG));
+ if (!partitionFunctionConfig.isEmpty()) {
+ partitionFunctionConfigMap = new HashMap<>();
+ Iterator<String> partitionFunctionConfigKeysIter =
partitionFunctionConfig.getKeys();
+ while (partitionFunctionConfigKeysIter.hasNext()) {
+ String functionConfigKey = partitionFunctionConfigKeysIter.next();
+ Object functionConfigValueObj =
partitionFunctionConfig.getProperty(functionConfigKey);
+ String valueStr;
+ if (functionConfigValueObj instanceof List) {
Review comment:
Let's add some comment here to describe this
##########
File path:
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/partition/BoundedColumnValuePartitionFunction.java
##########
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.spi.partition;
+
+import com.google.common.base.Preconditions;
+import java.util.Map;
+
+
+/**
+ * Implementation of {@link PartitionFunction} which partitions based
configured column values.
+ *
+ * "columnPartitionMap": {
+ * "subject": {
+ * "functionName": "BoundedColumnValue",
+ * "functionConfig": {
+ * "columnValues": "Maths|English|Chemistry"
Review comment:
Update the example to include `numPartitions` and `columnValuesDelimiter`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]