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/11/09 15:51:31 UTC

[GitHub] [ignite-3] AMashenkov opened a new pull request #435: IGNITE-14484 Implement RecordView API.

AMashenkov opened a new pull request #435:
URL: https://github.com/apache/ignite-3/pull/435


   https://issues.apache.org/jira/browse/IGNITE-14484


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



[GitHub] [ignite-3] ygerzhedovich commented on a change in pull request #435: IGNITE-14484 Implement RecordView API.

Posted by GitBox <gi...@apache.org>.
ygerzhedovich commented on a change in pull request #435:
URL: https://github.com/apache/ignite-3/pull/435#discussion_r748153418



##########
File path: modules/api/src/main/java/org/apache/ignite/table/mapper/MapperBuilder.java
##########
@@ -102,11 +105,24 @@
      * Builds mapper.
      *
      * @return Mapper.
+     * @throws IllegalStateException if nothing were mapped or more than one column were mapped to the same field.
      */
     public Mapper<T> build() {
-        Map<String, String> mapping = this.mapping;
+        if (columnToFields.isEmpty()) {
+            throw new IllegalStateException("Empty mapping doen't allowed.");

Review comment:
       ```suggestion
               throw new IllegalStateException("Empty mapping doesn't allowed.");
   ```




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



[GitHub] [ignite-3] ygerzhedovich commented on a change in pull request #435: IGNITE-14484 Implement RecordView API.

Posted by GitBox <gi...@apache.org>.
ygerzhedovich commented on a change in pull request #435:
URL: https://github.com/apache/ignite-3/pull/435#discussion_r748203664



##########
File path: modules/schema/src/main/java/org/apache/ignite/internal/schema/marshaller/reflection/RecordMarshallerImpl.java
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.marshaller.reflection;
+
+import static org.apache.ignite.internal.schema.marshaller.MarshallerUtil.getValueSize;
+
+import java.util.Objects;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.apache.ignite.internal.schema.ByteBufferRow;
+import org.apache.ignite.internal.schema.Columns;
+import org.apache.ignite.internal.schema.SchemaDescriptor;
+import org.apache.ignite.internal.schema.marshaller.MarshallerException;
+import org.apache.ignite.internal.schema.marshaller.RecordMarshaller;
+import org.apache.ignite.internal.schema.row.Row;
+import org.apache.ignite.internal.schema.row.RowAssembler;
+import org.apache.ignite.internal.util.ArrayUtils;
+import org.apache.ignite.table.mapper.Mapper;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Record marshaller for given schema and mappers.
+ *
+ * @param <R> Record type.
+ */
+public class RecordMarshallerImpl<R> implements RecordMarshaller<R> {
+    /** Schema. */
+    private final SchemaDescriptor schema;
+    
+    /** Key marshaller. */
+    private final Marshaller keyMarsh;
+    
+    /** Record marshaller. */
+    private final Marshaller recMarsh;
+    
+    /** Record type. */
+    private final Class<R> recClass;
+    
+    /**
+     * Creates KV marshaller.
+     */
+    public RecordMarshallerImpl(SchemaDescriptor schema, Mapper<R> mapper) {
+        this.schema = schema;
+        
+        recClass = mapper.targetType();
+        
+        keyMarsh = Marshaller.createMarshaller(schema.keyColumns().columns(), mapper);
+        
+        recMarsh = Marshaller.createMarshaller(
+                ArrayUtils.concat(schema.keyColumns().columns(), schema.valueColumns().columns()),
+                mapper
+        );
+    }
+    
+    /** {@inheritDoc} */
+    @Override
+    public int schemaVersion() {
+        return schema.version();
+    }
+    
+    /** {@inheritDoc} */
+    @Override
+    public BinaryRow marshal(@NotNull R rec) throws MarshallerException {
+        assert recClass.isInstance(rec);
+        
+        final RowAssembler asm = createAssembler(Objects.requireNonNull(rec), rec);
+        
+        recMarsh.writeObject(rec, asm);
+        
+        return new ByteBufferRow(asm.toBytes());
+    }
+    
+    /** {@inheritDoc} */
+    @Override
+    public BinaryRow marshalKey(@NotNull R rec) throws MarshallerException {
+        assert recClass.isInstance(rec);
+        
+        final RowAssembler asm = createAssembler(Objects.requireNonNull(rec), null);
+        
+        keyMarsh.writeObject(rec, asm);
+        
+        return new ByteBufferRow(asm.toBytes());
+    }
+    
+    /** {@inheritDoc} */
+    @NotNull
+    @Override
+    public R unmarshal(@NotNull Row row) throws MarshallerException {
+        final Object o = recMarsh.readObject(row);
+        
+        assert recClass.isInstance(o);
+        
+        return (R) o;
+    }
+    
+    /**
+     * Creates {@link RowAssembler} for key-value pair.
+     *
+     * @param key Key object.
+     * @param val Value object.
+     * @return Row assembler.
+     */
+    private RowAssembler createAssembler(Object key, Object val) {
+        ObjectStatistic keyStat = collectObjectStats(schema.keyColumns(), recMarsh, key);
+        ObjectStatistic valStat = collectObjectStats(schema.valueColumns(), recMarsh, val);
+        
+        return new RowAssembler(schema, keyStat.nonNullColsSize, keyStat.nonNullCols,
+                valStat.nonNullColsSize, valStat.nonNullCols);
+    }
+    
+    /**
+     * Reads object fields and gather statistic.
+     *
+     * @param cols  Schema columns.
+     * @param marsh Marshaller.
+     * @param obj   Object.
+     * @return Object statistic.
+     */
+    private ObjectStatistic collectObjectStats(Columns cols, Marshaller marsh, Object obj) {
+        if (obj == null || !cols.hasVarlengthColumns()) {
+            return ObjectStatistic.ZERO_VARLEN_STATISTICS;
+        }
+        
+        int cnt = 0;
+        int size = 0;
+        
+        for (int i = cols.firstVarlengthColumn(); i < cols.length(); i++) {
+            final Object val = marsh.value(obj, cols.column(i).schemaIndex());

Review comment:
       maybe it will be more convinient to extract variable for `cols.column(i)`




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



[GitHub] [ignite-3] AMashenkov merged pull request #435: IGNITE-14484 Implement RecordView API.

Posted by GitBox <gi...@apache.org>.
AMashenkov merged pull request #435:
URL: https://github.com/apache/ignite-3/pull/435


   


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