This is an automated email from the ASF dual-hosted git repository.
pfzhan pushed a commit to branch kylin5
in repository https://gitbox.apache.org/repos/asf/kylin.git
The following commit(s) were added to refs/heads/kylin5 by this push:
new 9284fa96a5 KYLIN-6030 rename table related api response attributes
9284fa96a5 is described below
commit 9284fa96a5b343e183036977de2076bbea187d03
Author: Guoliang Sun <[email protected]>
AuthorDate: Tue Feb 25 14:34:17 2025 +0800
KYLIN-6030 rename table related api response attributes
Co-authored-by: 夏旭晨 <[email protected]>
---
.../org/apache/kylin/metadata/model/TableDesc.java | 60 +++++++++++++++++++---
.../apache/kylin/metadata/model/TableDescTest.java | 41 +++++++++++++++
2 files changed, 93 insertions(+), 8 deletions(-)
diff --git
a/src/core-metadata/src/main/java/org/apache/kylin/metadata/model/TableDesc.java
b/src/core-metadata/src/main/java/org/apache/kylin/metadata/model/TableDesc.java
index d120342a02..d9d86fc4af 100644
---
a/src/core-metadata/src/main/java/org/apache/kylin/metadata/model/TableDesc.java
+++
b/src/core-metadata/src/main/java/org/apache/kylin/metadata/model/TableDesc.java
@@ -44,8 +44,10 @@ import org.apache.kylin.metadata.table.ATable;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
+import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonSetter;
import lombok.AllArgsConstructor;
import lombok.Getter;
@@ -92,10 +94,9 @@ public class TableDesc extends ATable implements
Serializable, ISourceAware {
@JsonProperty("table_type")
private String tableType;
- @Getter
- @Setter
- @JsonProperty("has_Internal")
- private boolean hasInternal = false;
+ private Boolean hasInternal;
+
+ private boolean hasInternalDeprecated = false;
//Sticky table
@Getter
@@ -180,10 +181,9 @@ public class TableDesc extends ATable implements
Serializable, ISourceAware {
@JsonProperty("transactional")
private boolean isTransactional;
- @Setter
- @Getter
- @JsonProperty("rangePartition")
- private boolean isRangePartition;
+ private Boolean isRangePartition;
+
+ private boolean rangePartitionDeprecated;
@Setter
@Getter
@@ -204,6 +204,8 @@ public class TableDesc extends ATable implements
Serializable, ISourceAware {
this.createTime = other.createTime;
this.name = other.name;
this.hasInternal = other.hasInternal;
+ this.hasInternalDeprecated = other.hasInternalDeprecated;
+ this.rangePartitionDeprecated = other.rangePartitionDeprecated;
this.sourceType = other.sourceType;
this.tableType = other.tableType;
this.dataGen = other.dataGen;
@@ -235,6 +237,48 @@ public class TableDesc extends ATable implements
Serializable, ISourceAware {
setMvcc(other.getMvcc());
}
+ @JsonGetter("range_partition")
+ public boolean isRangePartition() {
+ return isRangePartition == null ? rangePartitionDeprecated :
isRangePartition;
+ }
+
+ @JsonSetter("range_partition")
+ public void setRangePartition(boolean isRangePartition) {
+ this.isRangePartition = isRangePartition;
+ }
+
+ @JsonGetter("has_internal")
+ public boolean isHasInternal() {
+ return hasInternal == null ? hasInternalDeprecated : hasInternal;
+ }
+
+ @JsonSetter("has_internal")
+ public void setHasInternal(boolean hasInternal) {
+ this.hasInternal = hasInternal;
+ }
+
+ /**
+ * This setter exists for compatibility with older data versions
+ * that utilize the has_Internal json field. Please use {@link
TableDesc#setHasInternal} instead.
+ * @deprecated since 5.2.2
+ */
+ @JsonSetter("has_Internal")
+ @Deprecated
+ public void setHasInternalDeprecated(boolean hasInternalDeprecated) {
+ this.hasInternalDeprecated = hasInternalDeprecated;
+ }
+
+ /**
+ * This setter exists for compatibility with older data versions
+ * that utilize the rangePartition json field. Please use {@link
TableDesc#setRangePartition} instead.
+ * @deprecated since 5.2.2
+ */
+ @JsonSetter("rangePartition")
+ @Deprecated
+ public void setRangePartitionDeprecated(boolean rangePartitionDeprecated) {
+ this.rangePartitionDeprecated = rangePartitionDeprecated;
+ }
+
/**
* Streaming table can't be accessed when streaming disabled
*/
diff --git
a/src/core-metadata/src/test/java/org/apache/kylin/metadata/model/TableDescTest.java
b/src/core-metadata/src/test/java/org/apache/kylin/metadata/model/TableDescTest.java
index 89a0dee5a3..3cdc3ee00c 100644
---
a/src/core-metadata/src/test/java/org/apache/kylin/metadata/model/TableDescTest.java
+++
b/src/core-metadata/src/test/java/org/apache/kylin/metadata/model/TableDescTest.java
@@ -28,6 +28,10 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
public class TableDescTest extends NLocalFileMetadataTestCase {
private final String project = "default";
private NTableMetadataManager tableMetadataManager;
@@ -91,4 +95,41 @@ public class TableDescTest extends
NLocalFileMetadataTestCase {
// Test returned identity using config db
Assert.assertEquals("ANOTHER_DB.TEST_KYLIN_FACT_HIVE_TX_INTERMEDIATE",
tableDesc.getTransactionalTableIdentity("another_db"));
}
+
+ @Test
+ public void testFieldRenameSerialize() throws JsonProcessingException {
+ testSerDes("{\"has_Internal\":true,\"rangePartition\":false}", true,
false);
+
+ // test default value
+ testSerDes("{}", false, false);
+
+ testSerDes("{\"has_Internal\":true,\"rangePartition\":true,
\"has_internal\":false,\"range_partition\":false}",
+ false, false);
+ }
+
+ @Test
+ public void testConstructor() {
+ TableDesc tableDesc = new TableDesc();
+ tableDesc.setHasInternal(true);
+ tableDesc.setRangePartition(false);
+ // avoid NPE
+ tableDesc.setColumns(new ColumnDesc[0]);
+ TableDesc tableDesc1 = new TableDesc(tableDesc);
+ Assert.assertTrue(tableDesc1.isHasInternal());
+ Assert.assertFalse(tableDesc1.isRangePartition());
+ }
+
+ private static void testSerDes(String json, boolean isInternal, boolean
isRangePartition)
+ throws JsonProcessingException {
+ ObjectMapper mapper = new ObjectMapper();
+ TableDesc tableDesc = mapper.readValue(json, TableDesc.class);
+ Assert.assertEquals(isInternal, tableDesc.isHasInternal());
+ Assert.assertEquals(isRangePartition, tableDesc.isRangePartition());
+ String serializeJson = mapper.writeValueAsString(tableDesc);
+ JsonNode jsonNode = mapper.readTree(serializeJson);
+ Assert.assertEquals(isInternal,
jsonNode.get("has_internal").asBoolean());
+ Assert.assertEquals(isRangePartition,
jsonNode.get("range_partition").asBoolean());
+ Assert.assertNull(jsonNode.get("has_Internal"));
+ Assert.assertNull(jsonNode.get("rangePartition"));
+ }
}