You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2022/07/04 10:25:07 UTC

[GitHub] [ignite-3] ibessonov commented on a diff in pull request #898: IGNITE-17192 Binary Tuple Implementation

ibessonov commented on code in PR #898:
URL: https://github.com/apache/ignite-3/pull/898#discussion_r912861193


##########
modules/schema/src/main/java/org/apache/ignite/internal/schema/BinaryTupleReader.java:
##########
@@ -0,0 +1,537 @@
+/*
+ * 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.ignite.internal.schema;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.StandardCharsets;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.util.BitSet;
+import java.util.UUID;
+
+/**
+ * Utility for access to binary tuple elements as typed values.
+ */
+public class BinaryTupleReader extends BinaryTupleParser {
+    /** A helper to locate and handle tuple elements. */
+    private class ElementSink implements BinaryTupleParser.Sink {
+        int offset;
+        int length;
+
+        /** {@inheritDoc} */
+        @Override
+        public void nextElement(int index, int begin, int end) {
+            offset = begin;
+            length = end - begin;
+        }
+
+        boolean isNull() {
+            return offset == 0;
+        }
+
+        byte asByte() {
+            if (length == 0) {
+                return 0;
+            }
+            assert length == Byte.BYTES;
+            return buffer.get(offset);
+        }
+
+        short asShort() {
+            if (length == 0) {
+                return 0;
+            }
+            if (length == Byte.BYTES) {
+                return buffer.get(offset);
+            }
+            assert length == Short.BYTES;
+            return buffer.getShort(offset);
+        }
+
+        int asInt() {
+            if (length == 0) {
+                return 0;
+            }
+            if (length == Byte.BYTES) {
+                return buffer.get(offset);
+            }
+            if (length == Short.BYTES) {
+                return buffer.getShort(offset);
+            }
+            assert length == Integer.BYTES;
+            return buffer.getInt(offset);
+        }
+
+        long asLong() {
+            if (length == 0) {
+                return 0;
+            }
+            if (length == Byte.BYTES) {
+                return buffer.get(offset);
+            }
+            if (length == Short.BYTES) {
+                return buffer.getShort(offset);
+            }
+            if (length == Integer.BYTES) {
+                return buffer.getInt(offset);
+            }
+            assert length == Long.BYTES;
+            return buffer.getLong(offset);
+        }
+
+        float asFloat() {
+            if (length == 0) {
+                return 0.0F;
+            }
+            assert length == Float.BYTES;
+            return buffer.getFloat(offset);
+        }
+
+        double asDouble() {
+            if (length == 0) {
+                return 0.0;
+            }
+            if (length == Float.BYTES) {
+                return buffer.getFloat(offset);
+            }
+            assert length == Double.BYTES;
+            return buffer.getDouble(offset);
+        }
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param numElements Number of tuple elements.
+     * @param bytes Binary tuple.
+     */
+    public BinaryTupleReader(int numElements, byte[] bytes) {
+        this(numElements, ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN));
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param numElements Number of tuple elements.
+     * @param buffer Buffer with a binary tuple.
+     */
+    public BinaryTupleReader(int numElements, ByteBuffer buffer) {
+        super(numElements, buffer);
+    }
+
+    /**
+     * Get underlying buffer.
+     *
+     * @return Buffer.
+     */
+    public ByteBuffer getBuffer() {
+        return buffer;
+    }
+
+    /**
+     * Checks whether the given element contains a null value.
+     *
+     * @param index Element index.
+     * @return {@code true} if this element contains a null value, {@code false} otherwise.
+     */
+    public boolean hasNullValue(int index) {
+        return seek(index).isNull();
+    }
+
+    /**
+     * Reads value of specified element.
+     *
+     * @param index Element index.
+     * @return Element value.
+     */
+    public byte byteValue(int index) {
+        return seek(index).asByte();
+    }
+
+    /**
+     * Reads value of specified element.
+     *
+     * @param index Element index.
+     * @return Element value.
+     */
+    public Byte byteValueBoxed(int index) {
+        var element = seek(index);

Review Comment:
   I see, this one got ignored



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org