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/02 17:35:47 UTC

[GitHub] [ignite-3] AMashenkov opened a new pull request #424: IGNITE-15783 Mapper API and simple implementation.

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


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


-- 
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 #424: IGNITE-15783 Mapper API and simple implementation.

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



##########
File path: modules/schema/src/main/java/org/apache/ignite/internal/schema/NativeTypes.java
##########
@@ -195,6 +196,7 @@ public static NativeType timestamp() {
      * @param val Object to map to native type.
      * @return {@code null} for {@code null} value. Otherwise returns NativeType according to the value's type.
      */
+    @Contract("null -> null")

Review comment:
       What reason to add jetbrains annotations? I think we should start discussion at least internally before starting it.




-- 
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 commented on a change in pull request #424: IGNITE-15783 Mapper API and simple implementation.

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



##########
File path: modules/schema/src/main/java/org/apache/ignite/internal/schema/NativeTypes.java
##########
@@ -195,6 +196,7 @@ public static NativeType timestamp() {
      * @param val Object to map to native type.
      * @return {@code null} for {@code null} value. Otherwise returns NativeType according to the value's type.
      */
+    @Contract("null -> null")

Review comment:
       We already use jetbrains annotations in the project (see `@Nullable` and `@NotNull)`.
   The contract is clearly described in javadoc and the annotation just helps to suppress IDEA warning and affect nothing.




-- 
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 commented on a change in pull request #424: IGNITE-15783 Mapper API and simple implementation.

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



##########
File path: modules/schema/src/main/java/org/apache/ignite/internal/schema/NativeTypes.java
##########
@@ -195,6 +196,7 @@ public static NativeType timestamp() {
      * @param val Object to map to native type.
      * @return {@code null} for {@code null} value. Otherwise returns NativeType according to the value's type.
      */
+    @Contract("null -> null")

Review comment:
       We already use jetbrains annotations in the project (see `@Nullable` and `@NotNull)`.
   The contract is clearly described in javadoc and the annotation just helps to suppress IDEA warning and affect nothing.
   
   Proof: 
   `Note that this annotation just describes how the code works and doesn't add any functionality by means of code generation.`




-- 
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 #424: IGNITE-15783 Mapper API and simple implementation.

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



##########
File path: modules/api/src/main/java/org/apache/ignite/table/mapper/MapperBuilder.java
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.table.mapper;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Function;
+import org.apache.ignite.table.Tuple;
+
+/**
+ * Mapper builder.
+ *
+ * @param <T> Mapped type.
+ */
+public final class MapperBuilder<T> {
+    /** Target type. */
+    private Class<T> targetType;
+    
+    /** Column-to-field name mapping. */
+    private Map<String, String> mapping;
+    
+    /**
+     * Creates a mapper builder for a type.
+     *
+     * @param targetType Target type.
+     */
+    MapperBuilder(Class<T> targetType) {
+        this.targetType = targetType;
+        
+        mapping = new HashMap<>(targetType.getDeclaredFields().length);
+    }
+    
+    /**
+     * Add mapping for a field to a column.
+     *
+     * @param fieldName  Field name.
+     * @param columnName Column name.
+     * @return {@code this} for chaining.
+     */
+    public MapperBuilder<T> map(String fieldName, String columnName) {
+        if (mapping == null) {
+            throw new IllegalStateException("Mapper builder can't be reused.");
+        }
+        
+        if (mapping.put(columnName, fieldName) != null) {

Review comment:
       should we check that neither filedName nor columnName is not null?




-- 
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 commented on a change in pull request #424: IGNITE-15783 Mapper API and simple implementation.

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



##########
File path: modules/schema/src/main/java/org/apache/ignite/internal/schema/NativeTypes.java
##########
@@ -195,6 +196,7 @@ public static NativeType timestamp() {
      * @param val Object to map to native type.
      * @return {@code null} for {@code null} value. Otherwise returns NativeType according to the value's type.
      */
+    @Contract("null -> null")

Review comment:
       We already use jetbrains annotations in the project (see \@Nullable and \@NotNull).
   The contract is clearly described in javadoc and the annotation just helps to suppress IDEA warning and affect nothing.




-- 
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 #424: IGNITE-15783 Mapper API and simple implementation.

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


   


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