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 2021/12/08 19:39:34 UTC

[GitHub] [ignite-3] isapego commented on a change in pull request #497: IGNITE-14971 Thin client: Add RecordView

isapego commented on a change in pull request #497:
URL: https://github.com/apache/ignite-3/pull/497#discussion_r765158710



##########
File path: modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientSchema.java
##########
@@ -118,4 +153,103 @@ public int version() {
     public int keyColumnCount() {
         return keyColumnCount;
     }
+
+    public <T> Marshaller getMarshaller(Mapper mapper, TuplePart part) {
+        return getMarshallerCache(part).computeIfAbsent(mapper, m -> createMarshaller(m, part));
+    }
+
+    private Map<Mapper, Marshaller> getMarshallerCache(TuplePart part) {
+        switch (part) {
+            case KEY:
+                return keyMarshallers;
+
+            case VAL:
+                return valMarshallers;
+
+            default:
+                return marshallers;
+        }
+    }
+
+    private Marshaller createMarshaller(Mapper mapper, TuplePart part) {
+        int colCount = columns.length;
+        int firstColIdx = 0;
+
+        if (part == TuplePart.KEY) {
+            colCount = keyColumnCount();
+        } else if (part == TuplePart.VAL) {
+            colCount = columns.length - keyColumnCount;
+            firstColIdx = keyColumnCount;

Review comment:
       Let's use consistent variant here - either `keyColumnCount` or `keyColumnCount()`

##########
File path: modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientRecordView.java
##########
@@ -0,0 +1,321 @@
+/*
+ * 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.client.table;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.client.IgniteClientException;
+import org.apache.ignite.internal.client.proto.ClientMessagePacker;
+import org.apache.ignite.internal.client.proto.ClientMessageUnpacker;
+import org.apache.ignite.internal.client.proto.ClientOp;
+import org.apache.ignite.internal.client.proto.TuplePart;
+import org.apache.ignite.internal.marshaller.ClientMarshallerReader;
+import org.apache.ignite.internal.marshaller.ClientMarshallerWriter;
+import org.apache.ignite.internal.marshaller.MarshallerException;
+import org.apache.ignite.internal.marshaller.MarshallerUtil;
+import org.apache.ignite.table.InvokeProcessor;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.mapper.Mapper;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Client record view implementation.
+ */
+public class ClientRecordView<R> implements RecordView<R> {
+    /** Mapper. */
+    private final Mapper<R> recMapper;
+
+    /** Underlying table. */
+    private final ClientTable tbl;
+
+    /** Simple mapping mode. */
+    private final boolean isSimpleMapping;

Review comment:
       It is not obvious what does it mean and why should we return key if it's `true`. Maybe we should mention in comment that it means record type is a simple type.

##########
File path: modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientRecordView.java
##########
@@ -0,0 +1,321 @@
+/*
+ * 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.client.table;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.client.IgniteClientException;
+import org.apache.ignite.internal.client.proto.ClientMessagePacker;
+import org.apache.ignite.internal.client.proto.ClientMessageUnpacker;
+import org.apache.ignite.internal.client.proto.ClientOp;
+import org.apache.ignite.internal.client.proto.TuplePart;
+import org.apache.ignite.internal.marshaller.ClientMarshallerReader;
+import org.apache.ignite.internal.marshaller.ClientMarshallerWriter;
+import org.apache.ignite.internal.marshaller.MarshallerException;
+import org.apache.ignite.internal.marshaller.MarshallerUtil;
+import org.apache.ignite.table.InvokeProcessor;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.mapper.Mapper;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Client record view implementation.
+ */
+public class ClientRecordView<R> implements RecordView<R> {
+    /** Mapper. */
+    private final Mapper<R> recMapper;
+
+    /** Underlying table. */
+    private final ClientTable tbl;
+
+    /** Simple mapping mode. */
+    private final boolean isSimpleMapping;
+
+    /**
+     * Constructor.
+     *
+     * @param tbl Underlying table.
+     * @param recMapper Mapper.
+     */
+    public ClientRecordView(ClientTable tbl, Mapper<R> recMapper) {
+        this.tbl = tbl;
+        this.recMapper = recMapper;
+
+        isSimpleMapping = MarshallerUtil.mode(recMapper.targetType()) != null;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public R get(@NotNull R keyRec) {
+        return getAsync(keyRec).join();
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public @NotNull CompletableFuture<R> getAsync(@NotNull R keyRec) {
+        Objects.requireNonNull(keyRec);
+
+        return tbl.doSchemaOutInOpAsync(
+                ClientOp.TUPLE_GET,
+                (schema, out) -> writeRec(keyRec, schema, out, TuplePart.KEY),
+                (inSchema, in) -> readValRec(keyRec, inSchema, in));
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public Collection<R> getAll(@NotNull Collection<R> keyRecs) {
+        // TODO: Implement all operations (IGNITE-16087).
+        return null;

Review comment:
       Let's throw not implemented exception in such cases.




-- 
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