This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 5ab0c1adbfd Try to compatiable with 1.3.X view
5ab0c1adbfd is described below
commit 5ab0c1adbfdb72aa6338eb25d3c51e530b06a73c
Author: Lin Xintao <[email protected]>
AuthorDate: Tue Mar 18 16:04:49 2025 +0800
Try to compatiable with 1.3.X view
---
.../multi/FunctionViewExpression.java | 14 +++++++
.../viewExpression/unary/LikeViewExpression.java | 39 +++++++++++++++---
.../schema/LikeViewExpreesionSerDeTest.java | 48 ++++++++++++++++++++++
3 files changed, 95 insertions(+), 6 deletions(-)
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/view/viewExpression/multi/FunctionViewExpression.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/view/viewExpression/multi/FunctionViewExpression.java
index eace4347717..1f73f59ae00 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/view/viewExpression/multi/FunctionViewExpression.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/view/viewExpression/multi/FunctionViewExpression.java
@@ -199,4 +199,18 @@ public class FunctionViewExpression extends ViewExpression
{
public List<ViewExpression> getExpressions() {
return this.expressions;
}
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ FunctionViewExpression that = (FunctionViewExpression) obj;
+ return functionName.equals(that.functionName)
+ &&
functionAttributesKeyValueList.equals(that.functionAttributesKeyValueList)
+ && expressions.equals(that.expressions);
+ }
}
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/view/viewExpression/unary/LikeViewExpression.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/view/viewExpression/unary/LikeViewExpression.java
index 1c195727d5e..96c41008bdd 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/view/viewExpression/unary/LikeViewExpression.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/view/viewExpression/unary/LikeViewExpression.java
@@ -56,16 +56,20 @@ public class LikeViewExpression extends UnaryViewExpression
{
public LikeViewExpression(ByteBuffer byteBuffer) {
super(ViewExpression.deserialize(byteBuffer));
pattern = ReadWriteIOUtils.readString(byteBuffer);
+ // Read the flag to determine whether the current code is 1.3.x or 2.0.x.
+ // If it is 1.3.x, we expect to read a boolean value, assign it to isNot,
and set escape to
+ // empty.
+ // If it is 2.0.x, we expect to read a byte value containing 2, and then
read escape and isNot.
byte judge = ReadWriteIOUtils.readByte(byteBuffer);
switch (judge) {
case -1:
case 0:
- isNot = false;
escape = Optional.empty();
+ isNot = false;
break;
case 1:
- isNot = true;
escape = Optional.empty();
+ isNot = true;
break;
case 2:
if (ReadWriteIOUtils.readBool(byteBuffer)) {
@@ -74,6 +78,7 @@ public class LikeViewExpression extends UnaryViewExpression {
escape = Optional.empty();
}
isNot = ReadWriteIOUtils.readBool(byteBuffer);
+ break;
default:
throw new IllegalStateException("Unexpected value in
LikeViewExpression: " + judge);
}
@@ -83,6 +88,11 @@ public class LikeViewExpression extends UnaryViewExpression {
super(ViewExpression.deserialize(inputStream));
try {
pattern = ReadWriteIOUtils.readString(inputStream);
+ // Read the flag to determine whether the current code is 1.3.x or 2.0.x.
+ // If it is 1.3.x, we expect to read a boolean value, assign it to
isNot, and set escape to
+ // empty.
+ // If it is 2.0.x, we expect to read a byte value containing 2, and then
read escape and
+ // isNot.
byte judge = ReadWriteIOUtils.readByte(inputStream);
switch (judge) {
case -1:
@@ -141,10 +151,11 @@ public class LikeViewExpression extends
UnaryViewExpression {
}
@Override
- protected void serialize(ByteBuffer byteBuffer) {
+ public void serialize(ByteBuffer byteBuffer) {
super.serialize(byteBuffer);
ReadWriteIOUtils.write(pattern, byteBuffer);
- ReadWriteIOUtils.write(2, byteBuffer);
+ // This flag is added to be compatible with versions 1.3.x and 2.0.x
+ ReadWriteIOUtils.write((byte) 2, byteBuffer);
ReadWriteIOUtils.write(escape.isPresent(), byteBuffer);
if (escape.isPresent()) {
ReadWriteIOUtils.write(escape.get().toString(), byteBuffer);
@@ -153,10 +164,11 @@ public class LikeViewExpression extends
UnaryViewExpression {
}
@Override
- protected void serialize(OutputStream stream) throws IOException {
+ public void serialize(OutputStream stream) throws IOException {
super.serialize(stream);
ReadWriteIOUtils.write(pattern, stream);
- ReadWriteIOUtils.write(2, stream);
+ // This flag is added to be compatible with versions 1.3.x and 2.0.x
+ ReadWriteIOUtils.write((byte) 2, stream);
ReadWriteIOUtils.write(escape.isPresent(), stream);
if (escape.isPresent()) {
ReadWriteIOUtils.write(escape.get().toString(), stream);
@@ -177,4 +189,19 @@ public class LikeViewExpression extends
UnaryViewExpression {
public boolean isNot() {
return isNot;
}
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ final LikeViewExpression target = (LikeViewExpression) obj;
+ return expression.equals(target.expression)
+ && pattern.equals(target.pattern)
+ && escape.equals(target.escape)
+ && isNot == target.isNot;
+ }
}
diff --git
a/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/schema/LikeViewExpreesionSerDeTest.java
b/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/schema/LikeViewExpreesionSerDeTest.java
new file mode 100644
index 00000000000..a0d5500aa27
--- /dev/null
+++
b/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/schema/LikeViewExpreesionSerDeTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.iotdb.commons.schema;
+
+import
org.apache.iotdb.commons.schema.view.viewExpression.multi.FunctionViewExpression;
+import
org.apache.iotdb.commons.schema.view.viewExpression.unary.LikeViewExpression;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.nio.ByteBuffer;
+import java.util.Optional;
+
+public class LikeViewExpreesionSerDeTest {
+
+ @Test
+ public void testLikeViewExpression() {
+ FunctionViewExpression functionViewExpression = new
FunctionViewExpression("function");
+ LikeViewExpression likeViewExpression =
+ new LikeViewExpression(functionViewExpression, "%es%",
Optional.of('\\'), true);
+ byteBufferSerDeTest(likeViewExpression);
+ }
+
+ private void byteBufferSerDeTest(final LikeViewExpression
likeViewExpression) {
+ ByteBuffer buffer = ByteBuffer.allocate(1024);
+ likeViewExpression.serialize(buffer);
+ buffer.flip();
+ LikeViewExpression deserialized = new LikeViewExpression(buffer);
+ Assert.assertEquals(likeViewExpression, deserialized);
+ }
+}