vrajat commented on code in PR #15515: URL: https://github.com/apache/pinot/pull/15515#discussion_r2038802160
########## pinot-common/src/main/java/org/apache/pinot/common/metadata/ZKMetadataProvider.java: ########## @@ -376,6 +385,7 @@ public static boolean removeSegmentZKMetadata(ZkHelixPropertyStore<ZNRecord> pro return propertyStore.remove(constructPropertyStorePathForSegment(tableNameWithType, segmentName), AccessOption.PERSISTENT); } + Review Comment: nit: whitespace ########## pinot-spi/src/main/java/org/apache/pinot/spi/data/LogicalTable.java: ########## @@ -0,0 +1,123 @@ +/** + * 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.spi.data; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import java.io.File; +import java.io.IOException; +import java.io.Serializable; +import java.util.List; +import java.util.Objects; +import org.apache.pinot.spi.utils.JsonUtils; + + +@JsonIgnoreProperties(ignoreUnknown = true) +public class LogicalTable implements Serializable { + private String _tableName; + private List<String> _physicalTableNames; + private String _brokerTenant = "DefaultTenant"; Review Comment: Lets discuss if tenant is required. Also I am not sure if this is the right place to initialize it. ########## pinot-common/src/main/java/org/apache/pinot/common/utils/LogicalTableUtils.java: ########## @@ -0,0 +1,52 @@ +/** + * 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.common.utils; + +import java.io.IOException; +import javax.annotation.Nonnull; +import org.apache.helix.zookeeper.datamodel.ZNRecord; +import org.apache.pinot.spi.data.LogicalTable; + + +/** + * Utility class which contains {@link LogicalTable} related operations. + */ +public class LogicalTableUtils { + + private LogicalTableUtils() { + } + + /** + * Fetch {@link LogicalTable} from a {@link ZNRecord}. + */ + public static LogicalTable fromZNRecord(@Nonnull ZNRecord record) + throws IOException { + String tableJSON = record.getSimpleField("tableJSON"); + return LogicalTable.fromString(tableJSON); + } + + /** + * Wrap {@link LogicalTable} into a {@link ZNRecord}. + */ + public static ZNRecord toZNRecord(@Nonnull LogicalTable table) { + ZNRecord record = new ZNRecord(table.getTableName()); + record.setSimpleField("tableJSON", table.toSingleLineJsonString()); Review Comment: I know chose this field name :) Is this using a pattern similar to others ? What does schema and table use ? Is `logicalTableJSON` better ? ########## pinot-spi/src/main/java/org/apache/pinot/spi/data/LogicalTable.java: ########## @@ -0,0 +1,123 @@ +/** + * 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.spi.data; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import java.io.File; +import java.io.IOException; +import java.io.Serializable; +import java.util.List; +import java.util.Objects; +import org.apache.pinot.spi.utils.JsonUtils; + + +@JsonIgnoreProperties(ignoreUnknown = true) +public class LogicalTable implements Serializable { + private String _tableName; + private List<String> _physicalTableNames; + private String _brokerTenant = "DefaultTenant"; + + public static LogicalTable fromFile(File logicalTableFile) + throws IOException { + return JsonUtils.fileToObject(logicalTableFile, LogicalTable.class); + } + + public static LogicalTable fromString(String logicalTableString) + throws IOException { + return JsonUtils.stringToObject(logicalTableString, LogicalTable.class); + } + + public String getTableName() { + return _tableName; + } + + public void setTableName(String tableName) { + _tableName = tableName; + } + + public String getBrokerTenant() { + return _brokerTenant; + } + + public void setBrokerTenant(String brokerTenant) { + _brokerTenant = brokerTenant; + } + + public List<String> getPhysicalTableNames() { + return _physicalTableNames; + } + + public void setPhysicalTableNames(List<String> physicalTableNames) { + _physicalTableNames = physicalTableNames; + } + + private ObjectNode toJsonObject() { + ObjectNode node = JsonUtils.newObjectNode().put("tableName", _tableName).put("brokerTenant", _brokerTenant); + ArrayNode arrayNode = JsonUtils.newArrayNode(); + for (String physicalTableName : _physicalTableNames) { + arrayNode.add(physicalTableName); + } + node.set("physicalTableNames", arrayNode); + return node; + } + + /** + * Returns a single-line json string representation of the schema. + */ + public String toSingleLineJsonString() { + return toJsonObject().toString(); + } + + /** + * Returns a pretty json string representation of the schema. + */ + public String toPrettyJsonString() { + try { + return JsonUtils.objectToPrettyString(toJsonObject()); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } + LogicalTable that = (LogicalTable) object; + return Objects.equals(getTableName(), that.getTableName()) && Objects.equals(getBrokerTenant(), Review Comment: Since names are unique, only checking the table name is sufficient. -- 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: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org