morningman commented on a change in pull request #7149: URL: https://github.com/apache/incubator-doris/pull/7149#discussion_r757218068
########## File path: fe/fe-core/src/main/java/org/apache/doris/analysis/DataSortInfo.java ########## @@ -0,0 +1,104 @@ +// 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.doris.analysis; + +import org.apache.doris.common.io.Writable; +import org.apache.doris.thrift.TSortType; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.Map; + +public class DataSortInfo implements Writable { + public static final String DATA_SORT_PROPERTY_PREFIX = "data_sort"; + public static final String DATA_SORT_TYPE = "data_sort.sort_type"; + public static final String DATA_SORT_COL_NUM = "data_sort.col_num"; + + private TSortType sortType; + private int colNum; Review comment: Use Gson to serialize. You can refer to `DropDbInfo` And the thrift data struct `TSortType` can be convert to a new self defined enum ########## File path: fe/fe-core/src/main/java/org/apache/doris/analysis/DataSortInfo.java ########## @@ -0,0 +1,104 @@ +// 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.doris.analysis; + +import org.apache.doris.common.io.Writable; +import org.apache.doris.thrift.TSortType; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.Map; + +public class DataSortInfo implements Writable { + public static final String DATA_SORT_PROPERTY_PREFIX = "data_sort"; + public static final String DATA_SORT_TYPE = "data_sort.sort_type"; + public static final String DATA_SORT_COL_NUM = "data_sort.col_num"; + + private TSortType sortType; + private int colNum; + + public DataSortInfo() { + + } + + public DataSortInfo(Map<String, String> properties) { + if (properties != null && !properties.isEmpty()) { + if (properties.get(DATA_SORT_TYPE).equalsIgnoreCase("ZORDER")) { + this.sortType = TSortType.ZORDER; + } else { + this.sortType = TSortType.LEXICAL; + } + this.colNum = Integer.parseInt(properties.get(DATA_SORT_COL_NUM)); + } + } + + public DataSortInfo (TSortType sortType, int colNum) { + this.sortType = sortType; + this.colNum = colNum; + } + + public TSortType getSortType() { + return sortType; + } + + public void setSortType(TSortType sortType) { + this.sortType = sortType; + } + + public int getColNum() { + return colNum; + } + + public void setColNum(int colNum) { + this.colNum = colNum; + } + + @Override + public void write(DataOutput out) throws IOException { + out.writeInt(sortType.getValue()); + out.writeInt(colNum); + } + + public void readFields(DataInput in) throws IOException { + this.sortType = TSortType.findByValue(in.readInt()); + this.colNum = in.readInt(); + } + + public static DataSortInfo read(DataInput in) throws IOException { + TSortType sortType = TSortType.findByValue(in.readInt()); + int colNum = in.readInt(); + return new DataSortInfo(sortType, colNum); + } + + public boolean equals(DataSortInfo dataSortInfo) { + if (this.sortType != dataSortInfo.sortType) { + return false; + } + if (this.colNum != dataSortInfo.colNum) { + return false; + } + return true; + } + + public String getProperties() { Review comment: toString() maybe better? ########## File path: fe/fe-core/src/main/java/org/apache/doris/catalog/TableProperty.java ########## @@ -137,6 +151,11 @@ public void modifyTableProperties(Map<String, String> modifyProperties) { properties.putAll(modifyProperties); } + public void modifyTableProperties(DataSortInfo dataSortInfo) { Review comment: Change the method name ########## File path: fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java ########## @@ -197,6 +199,12 @@ public boolean dynamicPartitionExists() { && tableProperty.getDynamicPartitionProperty().isExist(); } + public boolean dataSortInfoExists() { + return tableProperty != null + && tableProperty.getDataSortInfo()!= null Review comment: ```suggestion && tableProperty.getDataSortInfo() != null ``` ########## File path: be/test/olap/skiplist_test.cpp ########## @@ -268,7 +271,7 @@ class ConcurrentTest { ConcurrentTest() : _mem_tracker(new MemTracker(-1)), _mem_pool(new MemPool(_mem_tracker.get())), - _list(TestComparator(), _mem_pool.get(), false) {} + _list(new TestComparator(), _mem_pool.get(), false) {} Review comment: Add `~ConcurrentTest()` to delete `_list` ########## File path: fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java ########## @@ -1714,6 +1729,10 @@ public TStorageFormat getStorageFormat() { return tableProperty.getStorageFormat(); } + public DataSortInfo getDataSortInfo() { + return tableProperty.getDataSortInfo(); Review comment: Check if `tableProperty` is null ########## File path: fe/fe-core/src/main/java/org/apache/doris/task/CreateReplicaTask.java ########## @@ -165,6 +202,10 @@ public TCreateTabletReq toThrift() { tSchema.setSchemaHash(schemaHash); tSchema.setKeysType(keysType.toThrift()); tSchema.setStorageType(storageType); + if (dataSortInfo != null) { + tSchema.setSortType(dataSortInfo.getSortType()); + tSchema.setSortColNum(dataSortInfo.getColNum()); Review comment: Better use default value instead of optional setting? ########## File path: fe/fe-core/src/main/java/org/apache/doris/common/util/PropertyAnalyzer.java ########## @@ -514,4 +516,43 @@ public static ReplicaAllocation analyzeReplicaAllocation(Map<String, String> pro } return replicaAlloc; } + + public static DataSortInfo analyzeDataSortInfo(Map<String, String> properties, KeysType keyType, + int keyCount, TStorageFormat storageFormat) throws AnalysisException { + if (properties == null || properties.isEmpty()) { + return new DataSortInfo(TSortType.LEXICAL, keyCount); + } + String sortMethod = "lexical"; Review comment: Use a static field. Or maybe using `TSortType.name()`? ########## File path: fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java ########## @@ -197,6 +199,12 @@ public boolean dynamicPartitionExists() { && tableProperty.getDynamicPartitionProperty().isExist(); } + public boolean dataSortInfoExists() { Review comment: The `LEXICAL` is also a type of "sort info". So I think the method name or method body should be changed to make it more consistent. ########## File path: fe/fe-core/src/main/java/org/apache/doris/common/util/PropertyAnalyzer.java ########## @@ -514,4 +516,43 @@ public static ReplicaAllocation analyzeReplicaAllocation(Map<String, String> pro } return replicaAlloc; } + + public static DataSortInfo analyzeDataSortInfo(Map<String, String> properties, KeysType keyType, + int keyCount, TStorageFormat storageFormat) throws AnalysisException { + if (properties == null || properties.isEmpty()) { + return new DataSortInfo(TSortType.LEXICAL, keyCount); + } + String sortMethod = "lexical"; + if (properties.containsKey(DataSortInfo.DATA_SORT_TYPE)) { + sortMethod = properties.remove(DataSortInfo.DATA_SORT_TYPE); + } + TSortType sortType = TSortType.LEXICAL; + if (sortMethod.equalsIgnoreCase("zorder")) { Review comment: use `TSortType.ZORDER.name()` instead of a raw string. ########## File path: fe/fe-core/src/main/java/org/apache/doris/analysis/DataSortInfo.java ########## @@ -0,0 +1,104 @@ +// 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.doris.analysis; + +import org.apache.doris.common.io.Writable; +import org.apache.doris.thrift.TSortType; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.Map; + +public class DataSortInfo implements Writable { + public static final String DATA_SORT_PROPERTY_PREFIX = "data_sort"; + public static final String DATA_SORT_TYPE = "data_sort.sort_type"; + public static final String DATA_SORT_COL_NUM = "data_sort.col_num"; + + private TSortType sortType; + private int colNum; + + public DataSortInfo() { + + } + + public DataSortInfo(Map<String, String> properties) { + if (properties != null && !properties.isEmpty()) { + if (properties.get(DATA_SORT_TYPE).equalsIgnoreCase("ZORDER")) { + this.sortType = TSortType.ZORDER; + } else { + this.sortType = TSortType.LEXICAL; + } + this.colNum = Integer.parseInt(properties.get(DATA_SORT_COL_NUM)); + } + } + + public DataSortInfo (TSortType sortType, int colNum) { + this.sortType = sortType; + this.colNum = colNum; + } + + public TSortType getSortType() { + return sortType; + } + + public void setSortType(TSortType sortType) { + this.sortType = sortType; + } + + public int getColNum() { + return colNum; + } + + public void setColNum(int colNum) { + this.colNum = colNum; + } + + @Override + public void write(DataOutput out) throws IOException { + out.writeInt(sortType.getValue()); + out.writeInt(colNum); + } + + public void readFields(DataInput in) throws IOException { Review comment: ```suggestion private void readFields(DataInput in) throws IOException { ``` -- 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]
