You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by am...@apache.org on 2021/06/25 16:19:05 UTC

[ignite-3] branch ignite-14743-compaction updated (680ca0b -> 04d44cd)

This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a change to branch ignite-14743-compaction
in repository https://gitbox.apache.org/repos/asf/ignite-3.git.


 discard 680ca0b  Minor optimization.
     new 04d44cd  Minor optimization.

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (680ca0b)
            \
             N -- N -- N   refs/heads/ignite-14743-compaction (04d44cd)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../internal/benchmarks/TupleMarshallerVarlenOnlyBenchmark.java    | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

[ignite-3] 01/01: Minor optimization.

Posted by am...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a commit to branch ignite-14743-compaction
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit 04d44cd5c8163f630a54d2bba75bfc0437461dd7
Author: Andrew Mashenkov <an...@gmail.com>
AuthorDate: Fri Jun 25 16:55:54 2021 +0300

    Minor optimization.
---
 .../main/java/org/apache/ignite/table/Tuple.java   |  5 +++--
 .../ignite/internal/table/RowChunkAdapter.java     | 11 +++++++++++
 .../org/apache/ignite/internal/table/TableRow.java | 23 ++++------------------
 .../ignite/internal/table/TupleBuilderImpl.java    |  4 ++--
 .../ignite/internal/table/TupleMarshallerImpl.java |  9 ++-------
 .../TupleMarshallerVarlenOnlyBenchmark.java        |  7 ++-----
 .../internal/table/impl/TestTupleBuilder.java      | 20 ++++++++-----------
 7 files changed, 32 insertions(+), 47 deletions(-)

diff --git a/modules/api/src/main/java/org/apache/ignite/table/Tuple.java b/modules/api/src/main/java/org/apache/ignite/table/Tuple.java
index c9e0374..93605d5 100644
--- a/modules/api/src/main/java/org/apache/ignite/table/Tuple.java
+++ b/modules/api/src/main/java/org/apache/ignite/table/Tuple.java
@@ -31,9 +31,10 @@ public interface Tuple {
      * Returns {@code true} if this tuple contains a column with the specified name.
      *
      * @param colName Column name.
-     * @return {@code true} if this tuple contains a column with the specified name. Otherwise returns {@code false}.
+     * @param def Default value.
+     * @return Column value if this tuple contains a column with the specified name. Otherwise returns {@code default}.
      */
-    boolean contains(String colName);
+    <T> T valueOrDefault(String colName, T def);
 
     /**
      * Gets column value for given column name.
diff --git a/modules/table/src/main/java/org/apache/ignite/internal/table/RowChunkAdapter.java b/modules/table/src/main/java/org/apache/ignite/internal/table/RowChunkAdapter.java
index 2e213f1..dc9ab74 100644
--- a/modules/table/src/main/java/org/apache/ignite/internal/table/RowChunkAdapter.java
+++ b/modules/table/src/main/java/org/apache/ignite/internal/table/RowChunkAdapter.java
@@ -33,6 +33,7 @@ public abstract class RowChunkAdapter implements Tuple {
     /**
      * @param colName Column name.
      * @return Column.
+     * @throws ColumnNotFoundException If column wasn't found.
      */
     @NotNull protected abstract Column columnByName(@NotNull String colName);
 
@@ -42,6 +43,16 @@ public abstract class RowChunkAdapter implements Tuple {
     protected abstract Row row();
 
     /** {@inheritDoc} */
+    @Override public <T> T valueOrDefault(String colName, T def) {
+        try {
+            return value(colName);
+        }
+        catch (ColumnNotFoundException ex) {
+            return def;
+        }
+    }
+
+    /** {@inheritDoc} */
     @Override public <T> T value(String colName) {
         final Column col = columnByName(colName);
 
diff --git a/modules/table/src/main/java/org/apache/ignite/internal/table/TableRow.java b/modules/table/src/main/java/org/apache/ignite/internal/table/TableRow.java
index 31ab606..de111e2 100644
--- a/modules/table/src/main/java/org/apache/ignite/internal/table/TableRow.java
+++ b/modules/table/src/main/java/org/apache/ignite/internal/table/TableRow.java
@@ -19,8 +19,8 @@ package org.apache.ignite.internal.table;
 
 import java.util.Objects;
 import org.apache.ignite.internal.schema.Column;
-import org.apache.ignite.internal.schema.row.Row;
 import org.apache.ignite.internal.schema.SchemaDescriptor;
+import org.apache.ignite.internal.schema.row.Row;
 import org.apache.ignite.table.Tuple;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -57,7 +57,7 @@ public class TableRow extends RowChunkAdapter {
         final Column col = schema.column(colName);
 
         if (col == null)
-            throw new IllegalArgumentException("Invalid column name: columnName=" + colName + ", schemaVersion=" + schema.version());
+            throw new ColumnNotFoundException("Invalid column name: columnName=" + colName + ", schemaVersion=" + schema.version());
 
         return col;
     }
@@ -81,11 +81,6 @@ public class TableRow extends RowChunkAdapter {
         return row;
     }
 
-    /** */
-    @Override public boolean contains(String colName) {
-        return schema.column(colName) != null;
-    }
-
     /** Key column chunk. */
     private class KeyRowChunk extends RowChunkAdapter {
         /** {@inheritDoc} */
@@ -100,15 +95,10 @@ public class TableRow extends RowChunkAdapter {
             final Column col = schema.column(colName);
 
             if (col == null || !schema.isKeyColumn(col.schemaIndex()))
-                throw new IllegalArgumentException("Invalid key column name: columnName=" + colName + ", schemaVersion=" + schema.version());
+                throw new ColumnNotFoundException("Invalid key column name: columnName=" + colName + ", schemaVersion=" + schema.version());
 
             return col;
         }
-
-        /** */
-        @Override public boolean contains(String colName) {
-            return schema.column(colName) != null;
-        }
     }
 
     /** Value column chunk. */
@@ -125,14 +115,9 @@ public class TableRow extends RowChunkAdapter {
             final Column col = schema.column(colName);
 
             if (col == null || schema.isKeyColumn(col.schemaIndex()))
-                throw new IllegalArgumentException("Invalid key column name: columnName=" + colName + ", schemaVersion=" + schema.version());
+                throw new ColumnNotFoundException("Invalid key column name: columnName=" + colName + ", schemaVersion=" + schema.version());
 
             return col;
         }
-
-        /** */
-        @Override public boolean contains(String colName) {
-            return schema.column(colName) != null;
-        }
     }
 }
diff --git a/modules/table/src/main/java/org/apache/ignite/internal/table/TupleBuilderImpl.java b/modules/table/src/main/java/org/apache/ignite/internal/table/TupleBuilderImpl.java
index 1d4aae4..10dcfcd 100644
--- a/modules/table/src/main/java/org/apache/ignite/internal/table/TupleBuilderImpl.java
+++ b/modules/table/src/main/java/org/apache/ignite/internal/table/TupleBuilderImpl.java
@@ -71,8 +71,8 @@ public class TupleBuilderImpl implements TupleBuilder, Tuple {
     }
 
     /** {@inheritDoc} */
-    @Override public boolean contains(String colName) {
-        return map.containsKey(colName);
+    @Override public <T> T valueOrDefault(String colName, T def) {
+        return (T)map.getOrDefault(colName, def);
     }
 
     @Override public <T> T value(String colName) {
diff --git a/modules/table/src/main/java/org/apache/ignite/internal/table/TupleMarshallerImpl.java b/modules/table/src/main/java/org/apache/ignite/internal/table/TupleMarshallerImpl.java
index dbca237..a863899 100644
--- a/modules/table/src/main/java/org/apache/ignite/internal/table/TupleMarshallerImpl.java
+++ b/modules/table/src/main/java/org/apache/ignite/internal/table/TupleMarshallerImpl.java
@@ -129,12 +129,7 @@ public class TupleMarshallerImpl implements TupleMarshaller {
      * @param tup Tuple.
      */
     private void writeColumn(RowAssembler rowAsm, Column col, Tuple tup) {
-        Object val;
-
-        if (!tup.contains(col.name()))
-            val = col.defaultValue();
-        else
-            val = tup.value(col.name());
+        Object val = tup.valueOrDefault(col.name(), col.defaultValue());
 
         if (val == null) {
             rowAsm.appendNull();
@@ -215,7 +210,7 @@ public class TupleMarshallerImpl implements TupleMarshaller {
         for (int i = cols.firstVarlengthColumn(); i < cols.length(); i++) {
             Column col = cols.column(i);
 
-            final Object val = tup.contains(col.name()) ? tup.value(col.name()) : col.defaultValue();
+            final Object val = tup.valueOrDefault(col.name(), col.defaultValue());
 
             if (val == null)
                 continue;
diff --git a/modules/table/src/test/java/org/apache/ignite/internal/benchmarks/TupleMarshallerVarlenOnlyBenchmark.java b/modules/table/src/test/java/org/apache/ignite/internal/benchmarks/TupleMarshallerVarlenOnlyBenchmark.java
index f831c42..de5b063 100644
--- a/modules/table/src/test/java/org/apache/ignite/internal/benchmarks/TupleMarshallerVarlenOnlyBenchmark.java
+++ b/modules/table/src/test/java/org/apache/ignite/internal/benchmarks/TupleMarshallerVarlenOnlyBenchmark.java
@@ -77,7 +77,7 @@ public class TupleMarshallerVarlenOnlyBenchmark {
 
     /** Nullable cols. */
     @Param({"true", "false"})
-    public boolean nullable = true;
+    public boolean nullable;
 
     /** Column types. */
     @Param({"string", "bytes"})
@@ -115,10 +115,7 @@ public class TupleMarshallerVarlenOnlyBenchmark {
             42,
             new Column[] {new Column("key", LONG, false)},
             IntStream.range(0, fieldsCount).boxed()
-                .map(i -> {
-
-                    return new Column("col" + i, useString ? STRING : BYTES, nullable);
-                })
+                .map(i -> new Column("col" + i, useString ? STRING : BYTES, nullable))
                 .toArray(Column[]::new)
         );
 
diff --git a/modules/table/src/test/java/org/apache/ignite/internal/table/impl/TestTupleBuilder.java b/modules/table/src/test/java/org/apache/ignite/internal/table/impl/TestTupleBuilder.java
index 00450cf..f8520dc 100644
--- a/modules/table/src/test/java/org/apache/ignite/internal/table/impl/TestTupleBuilder.java
+++ b/modules/table/src/test/java/org/apache/ignite/internal/table/impl/TestTupleBuilder.java
@@ -24,34 +24,30 @@ import java.util.UUID;
 import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.binary.BinaryObjects;
 import org.apache.ignite.table.Tuple;
+import org.apache.ignite.table.TupleBuilder;
 
 /**
  * Dummy table storage implementation.
  */
-public class TestTupleBuilder implements Tuple {
+public class TestTupleBuilder implements TupleBuilder, Tuple {
     /** Columns values. */
     private final Map<String, Object> map = new HashMap<>();
 
-    /**
-     * Constructor.
-     */
-    public TestTupleBuilder() {
-    }
-
-    public TestTupleBuilder set(String colName, Object value) {
+    /** {@inheritDoc} */
+    @Override public TestTupleBuilder set(String colName, Object value) {
         map.put(colName, value);
 
         return this;
     }
 
-    /** */
-    public Tuple build() {
+    /** {@inheritDoc} */
+    @Override public Tuple build() {
         return this;
     }
 
     /** {@inheritDoc} */
-    @Override public boolean contains(String colName) {
-        return map.containsKey(colName);
+    @Override public <T> T valueOrDefault(String colName, T def) {
+        return (T)map.getOrDefault(colName, def);
     }
 
     /** {@inheritDoc} */