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 2022/08/02 10:21:50 UTC
[ignite-3] branch main updated: IGNITE-14487: Table view bulk methods refactoring. (#964)
This is an automated email from the ASF dual-hosted git repository.
amashenkov pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new 538c024a0 IGNITE-14487: Table view bulk methods refactoring. (#964)
538c024a0 is described below
commit 538c024a018ad6ff21bfce0d29f4f0e9dc3ddb77
Author: Andrew V. Mashenkov <AM...@users.noreply.github.com>
AuthorDate: Tue Aug 2 13:21:44 2022 +0300
IGNITE-14487: Table view bulk methods refactoring. (#964)
---
.../schema/registry/SchemaRegistryImpl.java | 4 +-
.../internal/table/KeyValueBinaryViewImpl.java | 20 ++++++----
.../ignite/internal/table/KeyValueViewImpl.java | 43 +++++++++++-----------
.../internal/table/RecordBinaryViewImpl.java | 27 ++++++++------
.../ignite/internal/table/RecordViewImpl.java | 23 ++++++------
5 files changed, 64 insertions(+), 53 deletions(-)
diff --git a/modules/schema/src/main/java/org/apache/ignite/internal/schema/registry/SchemaRegistryImpl.java b/modules/schema/src/main/java/org/apache/ignite/internal/schema/registry/SchemaRegistryImpl.java
index f4c83d721..4aabf9bfa 100644
--- a/modules/schema/src/main/java/org/apache/ignite/internal/schema/registry/SchemaRegistryImpl.java
+++ b/modules/schema/src/main/java/org/apache/ignite/internal/schema/registry/SchemaRegistryImpl.java
@@ -148,7 +148,9 @@ public class SchemaRegistryImpl implements SchemaRegistry {
List<Row> rows = new ArrayList<>(binaryRows.size());
for (BinaryRow r : binaryRows) {
- rows.add(resolveInternal(r, curSchema));
+ if (r != null) {
+ rows.add(resolveInternal(r, curSchema));
+ }
}
return rows;
diff --git a/modules/table/src/main/java/org/apache/ignite/internal/table/KeyValueBinaryViewImpl.java b/modules/table/src/main/java/org/apache/ignite/internal/table/KeyValueBinaryViewImpl.java
index de010b3d1..645731b57 100644
--- a/modules/table/src/main/java/org/apache/ignite/internal/table/KeyValueBinaryViewImpl.java
+++ b/modules/table/src/main/java/org/apache/ignite/internal/table/KeyValueBinaryViewImpl.java
@@ -20,7 +20,7 @@ package org.apache.ignite.internal.table;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -475,8 +475,8 @@ public class KeyValueBinaryViewImpl extends AbstractTableView implements KeyValu
* @param rows Binary rows.
* @return Key-value pairs of tuples.
*/
- public Map<Tuple, Tuple> unmarshalValue(Collection<BinaryRow> rows) {
- Map<Tuple, Tuple> pairs = new HashMap<>();
+ private Map<Tuple, Tuple> unmarshalValue(Collection<BinaryRow> rows) {
+ Map<Tuple, Tuple> pairs = IgniteUtils.newHashMap(rows.size());
for (Row row : schemaReg.resolve(rows)) {
if (row.hasValue()) {
@@ -493,13 +493,15 @@ public class KeyValueBinaryViewImpl extends AbstractTableView implements KeyValu
* @param keys Key tuples.
* @return Rows.
*/
- public List<BinaryRowEx> marshalKeys(@NotNull Collection<Tuple> keys) {
+ private List<BinaryRowEx> marshalKeys(Collection<Tuple> keys) {
+ if (keys.isEmpty()) {
+ return Collections.emptyList();
+ }
+
List<BinaryRowEx> keyRows = new ArrayList<>(keys.size());
for (Tuple keyRec : keys) {
- final Row keyRow = marshal(Objects.requireNonNull(keyRec), null);
-
- keyRows.add(keyRow);
+ keyRows.add(marshal(Objects.requireNonNull(keyRec), null));
}
return keyRows;
}
@@ -511,6 +513,10 @@ public class KeyValueBinaryViewImpl extends AbstractTableView implements KeyValu
* @return Value tuple.
*/
private Collection<Tuple> unmarshalKeys(Collection<BinaryRow> rows) {
+ if (rows.isEmpty()) {
+ return Collections.emptyList();
+ }
+
List<Tuple> tuples = new ArrayList<>(rows.size());
for (Row row : schemaReg.resolve(rows)) {
diff --git a/modules/table/src/main/java/org/apache/ignite/internal/table/KeyValueViewImpl.java b/modules/table/src/main/java/org/apache/ignite/internal/table/KeyValueViewImpl.java
index 82db8bdd8..4d0871f33 100644
--- a/modules/table/src/main/java/org/apache/ignite/internal/table/KeyValueViewImpl.java
+++ b/modules/table/src/main/java/org/apache/ignite/internal/table/KeyValueViewImpl.java
@@ -21,7 +21,6 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -450,17 +449,18 @@ public class KeyValueViewImpl<K, V> extends AbstractTableView implements KeyValu
* @param keys Key objects.
* @return Binary rows.
*/
- @NotNull
- public Collection<BinaryRowEx> marshal(@NotNull Collection<K> keys) {
- final KvMarshaller<K, V> marsh = marshaller(schemaReg.lastSchemaVersion());
+ private Collection<BinaryRowEx> marshal(Collection<K> keys) {
+ if (keys.isEmpty()) {
+ return Collections.emptyList();
+ }
+
+ KvMarshaller<K, V> marsh = marshaller(schemaReg.lastSchemaVersion());
List<BinaryRowEx> keyRows = new ArrayList<>(keys.size());
try {
for (K key : keys) {
- final BinaryRowEx keyRow = marsh.marshal(Objects.requireNonNull(key));
-
- keyRows.add(keyRow);
+ keyRows.add(marsh.marshal(Objects.requireNonNull(key)));
}
} catch (MarshallerException e) {
throw new org.apache.ignite.lang.MarshallerException(e);
@@ -475,17 +475,18 @@ public class KeyValueViewImpl<K, V> extends AbstractTableView implements KeyValu
* @param pairs Key-value map.
* @return Binary rows.
*/
- @NotNull
- public List<BinaryRowEx> marshal(@NotNull Map<K, V> pairs) {
- final KvMarshaller<K, V> marsh = marshaller(schemaReg.lastSchemaVersion());
+ private List<BinaryRowEx> marshal(Map<K, V> pairs) {
+ if (pairs.isEmpty()) {
+ return Collections.emptyList();
+ }
+
+ KvMarshaller<K, V> marsh = marshaller(schemaReg.lastSchemaVersion());
List<BinaryRowEx> rows = new ArrayList<>(pairs.size());
try {
for (Map.Entry<K, V> pair : pairs.entrySet()) {
- final BinaryRowEx row = marsh.marshal(Objects.requireNonNull(pair.getKey()), pair.getValue());
-
- rows.add(row);
+ rows.add(marsh.marshal(Objects.requireNonNull(pair.getKey()), pair.getValue()));
}
} catch (MarshallerException e) {
throw new org.apache.ignite.lang.MarshallerException(e);
@@ -500,13 +501,12 @@ public class KeyValueViewImpl<K, V> extends AbstractTableView implements KeyValu
* @param rows Binary rows.
* @return Keys.
*/
- @NotNull
- public Collection<K> unmarshalKeys(Collection<BinaryRow> rows) {
+ private Collection<K> unmarshalKeys(Collection<BinaryRow> rows) {
if (rows.isEmpty()) {
return Collections.emptyList();
}
- final KvMarshaller<K, V> marsh = marshaller(schemaReg.lastSchemaVersion());
+ KvMarshaller<K, V> marsh = marshaller(schemaReg.lastSchemaVersion());
List<K> keys = new ArrayList<>(rows.size());
@@ -529,7 +529,7 @@ public class KeyValueViewImpl<K, V> extends AbstractTableView implements KeyValu
* @param binaryRow Binary row.
* @return Value object or {@code null} if not exists.
*/
- private V unmarshalNullableValue(BinaryRow binaryRow) {
+ private @Nullable V unmarshalNullableValue(@Nullable BinaryRow binaryRow) {
if (binaryRow == null || !binaryRow.hasValue()) {
return null;
}
@@ -551,15 +551,14 @@ public class KeyValueViewImpl<K, V> extends AbstractTableView implements KeyValu
* @param rows Binary rows.
* @return Key-value pairs.
*/
- @NotNull
- public Map<K, V> unmarshalPairs(Collection<BinaryRow> rows) {
+ private Map<K, V> unmarshalPairs(Collection<BinaryRow> rows) {
if (rows.isEmpty()) {
return Collections.emptyMap();
}
- final KvMarshaller<K, V> marsh = marshaller(schemaReg.lastSchemaVersion());
+ KvMarshaller<K, V> marsh = marshaller(schemaReg.lastSchemaVersion());
- Map<K, V> pairs = new HashMap<>(rows.size());
+ Map<K, V> pairs = IgniteUtils.newHashMap(rows.size());
try {
for (Row row : schemaReg.resolve(rows)) {
@@ -580,7 +579,7 @@ public class KeyValueViewImpl<K, V> extends AbstractTableView implements KeyValu
* @return Value object or {@code null} if not exists.
* @throws UnexpectedNullValueException if value object is null.
*/
- private V unmarshallValue(BinaryRow binaryRow) {
+ private @Nullable V unmarshallValue(@Nullable BinaryRow binaryRow) {
if (binaryRow == null) {
return null;
}
diff --git a/modules/table/src/main/java/org/apache/ignite/internal/table/RecordBinaryViewImpl.java b/modules/table/src/main/java/org/apache/ignite/internal/table/RecordBinaryViewImpl.java
index a9b5a3598..7b0327659 100644
--- a/modules/table/src/main/java/org/apache/ignite/internal/table/RecordBinaryViewImpl.java
+++ b/modules/table/src/main/java/org/apache/ignite/internal/table/RecordBinaryViewImpl.java
@@ -17,11 +17,10 @@
package org.apache.ignite.internal.table;
-import static java.util.stream.Collectors.toList;
-
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
@@ -356,14 +355,8 @@ public class RecordBinaryViewImpl extends AbstractTableView implements RecordVie
*
* @param row Binary row.
*/
- private Tuple wrap(BinaryRow row) {
- if (row == null) {
- return null;
- }
-
- final Row wrapped = schemaReg.resolve(row);
-
- return TableRow.tuple(wrapped);
+ private @Nullable Tuple wrap(@Nullable BinaryRow row) {
+ return row == null ? null : TableRow.tuple(schemaReg.resolve(row));
}
/**
@@ -372,7 +365,19 @@ public class RecordBinaryViewImpl extends AbstractTableView implements RecordVie
* @param rows Binary rows.
*/
private Collection<Tuple> wrap(Collection<BinaryRow> rows) {
- return rows.stream().filter(Objects::nonNull).map(schemaReg::resolve).map(TableRow::tuple).collect(toList());
+ if (rows.isEmpty()) {
+ return Collections.emptyList();
+ }
+
+ Collection<Tuple> wrapped = new ArrayList<>(rows.size());
+
+ for (Row row : schemaReg.resolve(rows)) {
+ if (row != null) {
+ wrapped.add(TableRow.tuple(row));
+ }
+ }
+
+ return wrapped;
}
/**
diff --git a/modules/table/src/main/java/org/apache/ignite/internal/table/RecordViewImpl.java b/modules/table/src/main/java/org/apache/ignite/internal/table/RecordViewImpl.java
index 4ccce3540..408eed526 100644
--- a/modules/table/src/main/java/org/apache/ignite/internal/table/RecordViewImpl.java
+++ b/modules/table/src/main/java/org/apache/ignite/internal/table/RecordViewImpl.java
@@ -337,8 +337,8 @@ public class RecordViewImpl<R> extends AbstractTableView implements RecordView<R
* @param rec Record object.
* @return Binary row.
*/
- private BinaryRowEx marshal(@NotNull R rec) {
- final RecordMarshaller<R> marsh = marshaller(schemaReg.lastSchemaVersion());
+ private BinaryRowEx marshal(R rec) {
+ RecordMarshaller<R> marsh = marshaller(schemaReg.lastSchemaVersion());
try {
return marsh.marshal(rec);
@@ -353,14 +353,14 @@ public class RecordViewImpl<R> extends AbstractTableView implements RecordView<R
* @param recs Records collection.
* @return Binary rows collection.
*/
- private Collection<BinaryRowEx> marshal(@NotNull Collection<R> recs) {
- final RecordMarshaller<R> marsh = marshaller(schemaReg.lastSchemaVersion());
+ private Collection<BinaryRowEx> marshal(Collection<R> recs) {
+ RecordMarshaller<R> marsh = marshaller(schemaReg.lastSchemaVersion());
List<BinaryRowEx> rows = new ArrayList<>(recs.size());
try {
for (R rec : recs) {
- final Row row = marsh.marshal(Objects.requireNonNull(rec));
+ Row row = marsh.marshal(Objects.requireNonNull(rec));
rows.add(row);
}
@@ -378,7 +378,7 @@ public class RecordViewImpl<R> extends AbstractTableView implements RecordView<R
* @return Binary row.
*/
private BinaryRowEx marshalKey(@NotNull R rec) {
- final RecordMarshaller<R> marsh = marshaller(schemaReg.lastSchemaVersion());
+ RecordMarshaller<R> marsh = marshaller(schemaReg.lastSchemaVersion());
try {
return marsh.marshalKey(rec);
@@ -393,14 +393,14 @@ public class RecordViewImpl<R> extends AbstractTableView implements RecordView<R
* @param recs Records collection.
* @return Binary rows collection.
*/
- private Collection<BinaryRowEx> marshalKeys(@NotNull Collection<R> recs) {
- final RecordMarshaller<R> marsh = marshaller(schemaReg.lastSchemaVersion());
+ private Collection<BinaryRowEx> marshalKeys(Collection<R> recs) {
+ RecordMarshaller<R> marsh = marshaller(schemaReg.lastSchemaVersion());
List<BinaryRowEx> rows = new ArrayList<>(recs.size());
try {
for (R rec : recs) {
- final Row row = marsh.marshalKey(Objects.requireNonNull(rec));
+ Row row = marsh.marshalKey(Objects.requireNonNull(rec));
rows.add(row);
}
@@ -439,13 +439,12 @@ public class RecordViewImpl<R> extends AbstractTableView implements RecordView<R
* @param rows Row collection.
* @return Records collection.
*/
- @NotNull
- public Collection<R> unmarshal(Collection<BinaryRow> rows) {
+ private Collection<R> unmarshal(Collection<BinaryRow> rows) {
if (rows.isEmpty()) {
return Collections.emptyList();
}
- final RecordMarshaller<R> marsh = marshaller(schemaReg.lastSchemaVersion());
+ RecordMarshaller<R> marsh = marshaller(schemaReg.lastSchemaVersion());
List<R> recs = new ArrayList<>(rows.size());