beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Work logged] (BEAM-4461) Create a library of useful transforms that use schemas
Date Wed, 05 Sep 2018 16:39:00 GMT

     [ https://issues.apache.org/jira/browse/BEAM-4461?focusedWorklogId=141410&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-141410
]

ASF GitHub Bot logged work on BEAM-4461:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 05/Sep/18 16:38
            Start Date: 05/Sep/18 16:38
    Worklog Time Spent: 10m 
      Work Description: akedin commented on a change in pull request #6317: [BEAM-4461]  Add
mapping between FieldType and Java types.
URL: https://github.com/apache/beam/pull/6317#discussion_r215343386
 
 

 ##########
 File path: sdks/java/core/src/test/java/org/apache/beam/sdk/schemas/FieldTypeDescriptorsTest.java
 ##########
 @@ -0,0 +1,160 @@
+/*
+ * 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.beam.sdk.schemas.transforms;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import org.apache.beam.sdk.schemas.FieldTypeDescriptors;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.schemas.Schema.FieldType;
+import org.apache.beam.sdk.values.TypeDescriptor;
+import org.apache.beam.sdk.values.TypeDescriptors;
+import org.joda.time.Instant;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+/** test for {@link FieldTypeDescriptors}. */
+public class FieldTypeDescriptorsTest {
+  @Test
+  public void testPrimitiveTypeToJavaType() {
+    assertEquals(
+        TypeDescriptors.bytes(), FieldTypeDescriptors.javaTypeForFieldType(FieldType.BYTE));
+    assertEquals(
+        TypeDescriptors.shorts(), FieldTypeDescriptors.javaTypeForFieldType(FieldType.INT16));
+    assertEquals(
+        TypeDescriptors.integers(), FieldTypeDescriptors.javaTypeForFieldType(FieldType.INT32));
+    assertEquals(
+        TypeDescriptors.longs(), FieldTypeDescriptors.javaTypeForFieldType(FieldType.INT64));
+    assertEquals(
+        TypeDescriptors.bigdecimals(),
+        FieldTypeDescriptors.javaTypeForFieldType(FieldType.DECIMAL));
+    assertEquals(
+        TypeDescriptors.floats(), FieldTypeDescriptors.javaTypeForFieldType(FieldType.FLOAT));
+    assertEquals(
+        TypeDescriptors.doubles(), FieldTypeDescriptors.javaTypeForFieldType(FieldType.DOUBLE));
+    assertEquals(
+        TypeDescriptors.strings(), FieldTypeDescriptors.javaTypeForFieldType(FieldType.STRING));
+    assertEquals(
+        TypeDescriptor.of(Instant.class),
+        FieldTypeDescriptors.javaTypeForFieldType(FieldType.DATETIME));
+    assertEquals(
+        TypeDescriptors.booleans(), FieldTypeDescriptors.javaTypeForFieldType(FieldType.BOOLEAN));
+    assertEquals(
+        TypeDescriptor.of(byte[].class),
+        FieldTypeDescriptors.javaTypeForFieldType(FieldType.BYTES));
+  }
+
+  @Test
+  public void testRowTypeToJavaType() {
+    assertEquals(
+        TypeDescriptors.lists(TypeDescriptors.rows()),
+        FieldTypeDescriptors.javaTypeForFieldType(
+            FieldType.array(FieldType.row(Schema.builder().build()))));
+  }
+
+  @Test
+  public void testArrayTypeToJavaType() {
+    assertEquals(
+        TypeDescriptors.lists(TypeDescriptors.longs()),
+        FieldTypeDescriptors.javaTypeForFieldType(FieldType.array(FieldType.INT64)));
+    assertEquals(
+        TypeDescriptors.lists(TypeDescriptors.lists(TypeDescriptors.longs())),
+        FieldTypeDescriptors.javaTypeForFieldType(
+            FieldType.array(FieldType.array(FieldType.INT64))));
+  }
+
+  @Test
+  public void testMapTypeToJavaType() {
+    assertEquals(
+        TypeDescriptors.maps(TypeDescriptors.strings(), TypeDescriptors.longs()),
+        FieldTypeDescriptors.javaTypeForFieldType(
+            FieldType.map(FieldType.STRING, FieldType.INT64)));
+    assertEquals(
+        TypeDescriptors.maps(
+            TypeDescriptors.strings(), TypeDescriptors.lists(TypeDescriptors.longs())),
+        FieldTypeDescriptors.javaTypeForFieldType(
+            FieldType.map(FieldType.STRING, FieldType.array(FieldType.INT64))));
+  }
+
+  @Test
+  public void testPrimitiveTypeToFieldType() {
+    assertEquals(
+        FieldType.BYTE, FieldTypeDescriptors.fieldTypeForJavaType(TypeDescriptors.bytes()));
+    assertEquals(
+        FieldType.INT16, FieldTypeDescriptors.fieldTypeForJavaType(TypeDescriptors.shorts()));
+    assertEquals(
+        FieldType.INT32, FieldTypeDescriptors.fieldTypeForJavaType(TypeDescriptors.integers()));
+    assertEquals(
+        FieldType.INT64, FieldTypeDescriptors.fieldTypeForJavaType(TypeDescriptors.longs()));
+    assertEquals(
+        FieldType.DECIMAL,
+        FieldTypeDescriptors.fieldTypeForJavaType(TypeDescriptors.bigdecimals()));
+    assertEquals(
+        FieldType.FLOAT, FieldTypeDescriptors.fieldTypeForJavaType(TypeDescriptors.floats()));
+    assertEquals(
+        FieldType.DOUBLE, FieldTypeDescriptors.fieldTypeForJavaType(TypeDescriptors.doubles()));
+    assertEquals(
+        FieldType.STRING, FieldTypeDescriptors.fieldTypeForJavaType(TypeDescriptors.strings()));
+    assertEquals(
+        FieldType.DATETIME,
+        FieldTypeDescriptors.fieldTypeForJavaType(TypeDescriptor.of(Instant.class)));
+    assertEquals(
+        FieldType.BOOLEAN, FieldTypeDescriptors.fieldTypeForJavaType(TypeDescriptors.booleans()));
+    assertEquals(
+        FieldType.BYTES,
+        FieldTypeDescriptors.fieldTypeForJavaType(TypeDescriptor.of(byte[].class)));
+  }
+
+  @Rule public transient ExpectedException thrown = ExpectedException.none();
+
+  @Test
+  public void testRowTypeToFieldType() {
+    thrown.expect(IllegalArgumentException.class);
 
 Review comment:
   nit: Add assertion for a part of the exception message?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 141410)
    Time Spent: 4h 50m  (was: 4h 40m)

> Create a library of useful transforms that use schemas
> ------------------------------------------------------
>
>                 Key: BEAM-4461
>                 URL: https://issues.apache.org/jira/browse/BEAM-4461
>             Project: Beam
>          Issue Type: Sub-task
>          Components: sdk-java-core
>            Reporter: Reuven Lax
>            Assignee: Reuven Lax
>            Priority: Major
>          Time Spent: 4h 50m
>  Remaining Estimate: 0h
>
> e.g. JoinBy(fields). Project, Filter, etc.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message