JingsongLi commented on a change in pull request #54:
URL: https://github.com/apache/flink-table-store/pull/54#discussion_r831706369
##########
File path:
flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/TableStore.java
##########
@@ -171,6 +181,83 @@ private FileStore buildFileStore() {
tableIdentifier, options, user, partitionType, keyType,
valueType, mergeFunction);
}
+ //
--------------------------------------------------------------------------------------------
+
+ /** A builder for constructing a immutable {@link TableStore}. */
+ public static final class TableStoreBuilder {
+
+ private Configuration options;
+ private ObjectIdentifier tableIdentifier;
+ private RowType type;
+
+ private List<String> primaryKeys = new ArrayList<>();
+ private List<String> partitionKeys = new ArrayList<>();
+ private String user = UUID.randomUUID().toString();
+
+ public TableStoreBuilder withConfiguration(Configuration options) {
+ this.options = options;
+ return this;
+ }
+
+ public TableStoreBuilder withTableIdentifier(ObjectIdentifier
tableIdentifier) {
+ this.tableIdentifier = tableIdentifier;
+ return this;
+ }
+
+ public TableStoreBuilder withSchema(RowType type) {
+ this.type = type;
+ return this;
+ }
+
+ public TableStoreBuilder withPrimaryKeys(List<String> primaryKeys) {
+ this.primaryKeys = primaryKeys;
+ return this;
+ }
+
+ public TableStoreBuilder withPartitionKeys(List<String> partitionKeys)
{
+ this.partitionKeys = partitionKeys;
+ return this;
+ }
+
+ public TableStoreBuilder withUser(String user) {
+ this.user = user;
+ return this;
+ }
+
+ public TableStore build() {
+ List<int[]> indices = adjustAndValidate();
+ return new TableStore(
+ options, tableIdentifier, type, indices.get(0),
indices.get(1), user);
+ }
+
+ private List<int[]> adjustAndValidate() {
Review comment:
A simpler approach would be:
```
public TableStore withPartitions(int[] partitions) {
this.partitions = partitions;
adjustAndValidateKeys();
return this;
}
public TableStore withPrimaryKeys(int[] primaryKeys) {
this.primaryKeys = primaryKeys;
adjustAndValidateKeys();
return this;
}
public void adjustAndValidateKeys() {
// ... do validate and adjust
}
```
##########
File path:
flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/TableStore.java
##########
@@ -171,6 +181,83 @@ private FileStore buildFileStore() {
tableIdentifier, options, user, partitionType, keyType,
valueType, mergeFunction);
}
+ //
--------------------------------------------------------------------------------------------
+
+ /** A builder for constructing a immutable {@link TableStore}. */
+ public static final class TableStoreBuilder {
Review comment:
I think we don't need a builder, actually, `TableStore` is a builder.
--
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]