This is an automated email from the ASF dual-hosted git repository. caogaofei pushed a commit to branch new-table-model-debug in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit c5d31e6ddcdc55a050d577c10c6447517e6fef0f Author: Beyyes <[email protected]> AuthorDate: Wed May 22 17:47:29 2024 +0800 add serialize and deserialize method for Cast, FunctionCall, GenericDataType, Identifier --- .../apache/iotdb/db/relational/sql/tree/Cast.java | 27 +++++++++++ .../iotdb/db/relational/sql/tree/Expression.java | 12 +++++ .../iotdb/db/relational/sql/tree/FunctionCall.java | 33 +++++++++++++ .../db/relational/sql/tree/GenericDataType.java | 23 +++++++++ .../iotdb/db/relational/sql/tree/Identifier.java | 23 +++++++++ .../db/relational/sql/tree/QualifiedName.java | 54 ++++++++++++++++++++++ .../relational/sql/tree/TableExpressionType.java | 4 ++ 7 files changed, 176 insertions(+) diff --git a/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/Cast.java b/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/Cast.java index c108f8e74ba..b671f5928f0 100644 --- a/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/Cast.java +++ b/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/Cast.java @@ -19,10 +19,15 @@ package org.apache.iotdb.db.relational.sql.tree; +import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils; + import com.google.common.collect.ImmutableList; import javax.annotation.Nonnull; +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; import java.util.List; import java.util.Objects; @@ -130,4 +135,26 @@ public final class Cast extends Expression { Cast otherCast = (Cast) other; return safe == otherCast.safe && typeOnly == otherCast.typeOnly; } + + // =============== serialize ================= + @Override + public TableExpressionType getExpressionType() { + return TableExpressionType.CAST; + } + + @Override + public void serialize(DataOutputStream stream) throws IOException { + Expression.serialize(this.expression, stream); + // ReadWriteIOUtils.write(this.type, stream); + ReadWriteIOUtils.write(this.safe, stream); + ReadWriteIOUtils.write(this.typeOnly, stream); + } + + public Cast(ByteBuffer byteBuffer) { + super(null); + this.expression = Expression.deserialize(byteBuffer); + this.type = null; + this.safe = ReadWriteIOUtils.readBool(byteBuffer); + this.typeOnly = ReadWriteIOUtils.readBool(byteBuffer); + } } diff --git a/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/Expression.java b/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/Expression.java index 260c8b46271..5059c2af3e4 100644 --- a/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/Expression.java +++ b/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/Expression.java @@ -91,6 +91,18 @@ public abstract class Expression extends Node { case 6: expression = new IsNullPredicate(byteBuffer); break; + case 7: + expression = new FunctionCall(byteBuffer); + break; + case 8: + expression = new Identifier(byteBuffer); + break; + case 9: + expression = new Cast(byteBuffer); + break; + case 10: + expression = new GenericDataType(byteBuffer); + break; case 11: expression = new BetweenPredicate(byteBuffer); break; diff --git a/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/FunctionCall.java b/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/FunctionCall.java index 8e2b4acf355..5bbff720ece 100644 --- a/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/FunctionCall.java +++ b/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/FunctionCall.java @@ -19,8 +19,14 @@ package org.apache.iotdb.db.relational.sql.tree; +import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils; + import com.google.common.collect.ImmutableList; +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -110,4 +116,31 @@ public class FunctionCall extends Expression { return name.equals(otherFunction.name) && distinct == otherFunction.distinct; } + + // =============== serialize ================= + @Override + public TableExpressionType getExpressionType() { + return TableExpressionType.FUNCTION_CALL; + } + + @Override + public void serialize(DataOutputStream stream) throws IOException { + this.name.serialize(stream); + ReadWriteIOUtils.write(this.distinct, stream); + ReadWriteIOUtils.write(arguments.size(), stream); + for (Expression argument : arguments) { + Expression.serialize(argument, stream); + } + } + + public FunctionCall(ByteBuffer byteBuffer) { + super(null); + this.name = QualifiedName.deserialize(byteBuffer); + this.distinct = ReadWriteIOUtils.readBool(byteBuffer); + int size = ReadWriteIOUtils.readInt(byteBuffer); + this.arguments = new ArrayList<>(size); + while (size-- > 0) { + arguments.add(Expression.deserialize(byteBuffer)); + } + } } diff --git a/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/GenericDataType.java b/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/GenericDataType.java index f5c39eae80e..5dfbcb8f568 100644 --- a/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/GenericDataType.java +++ b/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/GenericDataType.java @@ -19,10 +19,15 @@ package org.apache.iotdb.db.relational.sql.tree; +import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils; + import com.google.common.collect.ImmutableList; import javax.annotation.Nonnull; +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; import java.util.List; import java.util.Objects; @@ -85,4 +90,22 @@ public final class GenericDataType extends DataType { public boolean shallowEquals(Node other) { return sameClass(this, other); } + + // =============== serialize ================= + @Override + public TableExpressionType getExpressionType() { + return TableExpressionType.GENERIC_DATA_TYPE; + } + + @Override + public void serialize(DataOutputStream stream) throws IOException { + Expression.serialize(name, stream); + ReadWriteIOUtils.write(arguments.size(), stream); + } + + public GenericDataType(ByteBuffer byteBuffer) { + super(null); + this.name = (Identifier) Expression.deserialize(byteBuffer); + this.arguments = null; + } } diff --git a/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/Identifier.java b/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/Identifier.java index eb69f6d608c..43b5d3f83f5 100644 --- a/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/Identifier.java +++ b/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/Identifier.java @@ -19,10 +19,15 @@ package org.apache.iotdb.db.relational.sql.tree; +import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils; + import com.google.common.base.CharMatcher; import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; import java.util.List; import java.util.Objects; @@ -143,4 +148,22 @@ public class Identifier extends Expression { // so to avoid copying we are checking whole string. return ALLOWED_CHARS_MATCHER.matchesAllOf(value); } + + // =============== serialize ================= + @Override + public TableExpressionType getExpressionType() { + return TableExpressionType.IDENTIFIER; + } + + @Override + public void serialize(DataOutputStream stream) throws IOException { + ReadWriteIOUtils.write(this.value, stream); + ReadWriteIOUtils.write(this.delimited, stream); + } + + public Identifier(ByteBuffer byteBuffer) { + super(null); + this.value = ReadWriteIOUtils.readString(byteBuffer); + this.delimited = ReadWriteIOUtils.readBool(byteBuffer); + } } diff --git a/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/QualifiedName.java b/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/QualifiedName.java index 4b62f96b85f..c154f82343e 100644 --- a/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/QualifiedName.java +++ b/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/QualifiedName.java @@ -19,11 +19,17 @@ package org.apache.iotdb.db.relational.sql.tree; +import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils; + import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import javax.annotation.Nullable; +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -136,4 +142,52 @@ public class QualifiedName { public String toString() { return name; } + + public void serialize(DataOutputStream stream) throws IOException { + ReadWriteIOUtils.write(originalParts.size(), stream); + for (Identifier identifier : originalParts) { + Expression.serialize(identifier, stream); + } + + // ReadWriteIOUtils.write(parts.size(), stream); + // for (String part : parts) { + // ReadWriteIOUtils.write(part, stream); + // } + // + // ReadWriteIOUtils.write(name, stream); + // + // if (prefix != null) { + // ReadWriteIOUtils.write((byte)1, stream); + // prefix.serialize(stream); + // } else { + // ReadWriteIOUtils.write((byte)0, stream); + // } + // + // ReadWriteIOUtils.write(suffix, stream); + } + + public static QualifiedName deserialize(ByteBuffer byteBuffer) { + int size = ReadWriteIOUtils.read(byteBuffer); + List<Identifier> originalParts = new ArrayList<>(size); + while (size-- > 0) { + originalParts.add((Identifier) Expression.deserialize(byteBuffer)); + } + + // String name = ReadWriteIOUtils.readString(byteBuffer); + // + // size = ReadWriteIOUtils.read(byteBuffer); + // List<String> parts = new ArrayList<>(size); + // while (size -- > 0) { + // parts.add(ReadWriteIOUtils.readString(byteBuffer)); + // } + // + // byte hasPrefixByte = ReadWriteIOUtils.readByte(byteBuffer); + // if (hasPrefixByte == 1) { + // QualifiedName prefix = QualifiedName.deserialize(byteBuffer); + // } + // + // String suffix = ReadWriteIOUtils.readString(byteBuffer); + + return new QualifiedName(originalParts); + } } diff --git a/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/TableExpressionType.java b/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/TableExpressionType.java index 722c4024350..9edbe98112c 100644 --- a/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/TableExpressionType.java +++ b/iotdb-core/relational-parser/src/main/java/org/apache/iotdb/db/relational/sql/tree/TableExpressionType.java @@ -26,6 +26,10 @@ public enum TableExpressionType { IN_LIST((short) 4), IS_NOT_NULL_PREDICATE((short) 5), IS_NULL_PREDICATE((short) 6), + FUNCTION_CALL((short) 7), + IDENTIFIER((short) 8), + CAST((short) 9), + GENERIC_DATA_TYPE((short) 10), BETWEEN((short) 11), IN_PREDICATE((short) 12), LOGICAL_EXPRESSION((short) 13),
