[
https://issues.apache.org/jira/browse/BEAM-3437?focusedWorklogId=86857&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-86857
]
ASF GitHub Bot logged work on BEAM-3437:
----------------------------------------
Author: ASF GitHub Bot
Created on: 03/Apr/18 00:04
Start Date: 03/Apr/18 00:04
Worklog Time Spent: 10m
Work Description: akedin commented on a change in pull request #4964:
[BEAM-3437] Introduce Schema class, and use it in BeamSQL
URL: https://github.com/apache/beam/pull/4964#discussion_r178619006
##########
File path:
sdks/java/core/src/main/java/org/apache/beam/sdk/coders/BigEndianShortCoder.java
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.coders;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UTFDataFormatException;
+import org.apache.beam.sdk.values.TypeDescriptor;
+
+/**
+ * A {@link BigEndianShortCoder} encodes {@link Short Shorts} in 4 bytes,
big-endian.
+ */
+public class BigEndianShortCoder extends AtomicCoder<Short> {
+
+ public static BigEndianShortCoder of() {
+ return INSTANCE;
+ }
+
+ /////////////////////////////////////////////////////////////////////////////
+
+ private static final BigEndianShortCoder INSTANCE = new
BigEndianShortCoder();
+ private static final TypeDescriptor<Short> TYPE_DESCRIPTOR = new
TypeDescriptor<Short>() {};
+
+ private BigEndianShortCoder() {}
+
+ @Override
+ public void encode(Short value, OutputStream outStream) throws IOException {
+ if (value == null) {
+ throw new CoderException("cannot encode a null Short");
+ }
+ new DataOutputStream(outStream).writeShort(value);
Review comment:
I think it will make sense to refactor these coders eventually, i'd create a
jira to:
1. Stop allocating new `DataOutputStream` for each value read/write. Maybe
copy the implementation into a static utility class;
2. Extract some base classes/builders. From the looks of it, a ton of code
for numeric values coders is duplicated, we could probably simplify this with
inheritance/composition, probably along the lines of:
```java
class PrimitiveNumericCoder<T> {
// all the duplicate code.
// type descriptor should still work based on the current instance.
}
class BigEndianShortCoder extends PrimitiveNumericCoder<Short> {
public BigEndianShortCoder() {
super("Short", DataStreamUtils::encodeShort, 2);
}
}
class FloatCoder extends PrimitiveNumericCoder<Short> {
public BigEndianShortCoder() {
super("Float", DataStreamUtils::encodeFloat, 4);
}
}
```
----------------------------------------------------------------
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:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 86857)
Time Spent: 3.5h (was: 3h 20m)
> Support schema in PCollections
> ------------------------------
>
> Key: BEAM-3437
> URL: https://issues.apache.org/jira/browse/BEAM-3437
> Project: Beam
> Issue Type: Wish
> Components: beam-model
> Reporter: Jean-Baptiste Onofré
> Assignee: Jean-Baptiste Onofré
> Priority: Major
> Time Spent: 3.5h
> Remaining Estimate: 0h
>
> As discussed with some people in the team, it would be great to add schema
> support in {{PCollections}}. It will allow us:
> 1. To expect some data type in {{PTransforms}}
> 2. Improve some runners with additional features (I'm thinking about Spark
> runner with data frames for instance).
> A technical draft document has been created:
> https://docs.google.com/document/d/1tnG2DPHZYbsomvihIpXruUmQ12pHGK0QIvXS1FOTgRc/edit?disco=AAAABhykQIs&ts=5a203b46&usp=comment_email_document
> I also started a PoC on a branch, I will update this Jira with a "discussion"
> PR.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)