[
https://issues.apache.org/jira/browse/BEAM-7886?focusedWorklogId=292369&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-292369
]
ASF GitHub Bot logged work on BEAM-7886:
----------------------------------------
Author: ASF GitHub Bot
Created on: 10/Aug/19 00:31
Start Date: 10/Aug/19 00:31
Worklog Time Spent: 10m
Work Description: TheNeuralBit commented on pull request #9188:
[BEAM-7886] Make row coder a standard coder and implement in Python
URL: https://github.com/apache/beam/pull/9188#discussion_r312681991
##########
File path: sdks/python/apache_beam/typehints/schemas.py
##########
@@ -0,0 +1,163 @@
+#
+# 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.
+#
+
+from __future__ import absolute_import
+
+from typing import List
+from typing import Mapping
+from typing import NamedTuple
+from typing import Optional
+from uuid import uuid4
+
+import numpy as np
+
+from apache_beam.portability.api import schema_pb2
+from apache_beam.typehints.native_type_compatibility import _get_args
+from apache_beam.typehints.native_type_compatibility import
_match_is_exactly_mapping
+from apache_beam.typehints.native_type_compatibility import
_match_is_named_tuple
+from apache_beam.typehints.native_type_compatibility import _match_is_optional
+from apache_beam.typehints.native_type_compatibility import _safe_issubclass
+from apache_beam.typehints.native_type_compatibility import
extract_optional_type
+
+
+# Registry of typings for a schema by UUID
+class SchemaTypeRegistry(object):
+ def __init__(self):
+ self.by_id = {}
+ self.by_typing = {}
+
+ def add(self, typing, schema):
+ self.by_id[schema.id] = (typing, schema)
+
+ def get_typing_by_id(self, unique_id):
+ result = self.by_id.get(unique_id, None)
+ return result[0] if result is not None else None
+
+ def get_schema_by_id(self, unique_id):
+ result = self.by_id.get(unique_id, None)
+ return result[1] if result is not None else None
+
+
+SCHEMA_REGISTRY = SchemaTypeRegistry()
+
+
+_PRIMITIVES = (
+ (np.int8, schema_pb2.AtomicType.BYTE),
+ (np.int16, schema_pb2.AtomicType.INT16),
+ (np.int32, schema_pb2.AtomicType.INT32),
+ (np.int64, schema_pb2.AtomicType.INT64),
+ (np.float32, schema_pb2.AtomicType.FLOAT),
+ (np.float64, schema_pb2.AtomicType.DOUBLE),
+ (np.unicode, schema_pb2.AtomicType.STRING),
+ (np.bool, schema_pb2.AtomicType.BOOLEAN),
+ (np.bytes_, schema_pb2.AtomicType.BYTES),
Review comment:
This works in python 3, but in python 2 it would make a str map to BYTES.
I've updated this mapping as @robertwb suggested on the mailing list:
- In python 2 str/bytes maps to STRING, and types.ByteString is the only way
to specify BYTES.
- In python 3, str/unicode maps to STRING, and bytes and types.ByteString
both map to BYTES.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 292369)
Time Spent: 1h 50m (was: 1h 40m)
> Make row coder a standard coder and implement in python
> -------------------------------------------------------
>
> Key: BEAM-7886
> URL: https://issues.apache.org/jira/browse/BEAM-7886
> Project: Beam
> Issue Type: Improvement
> Components: beam-model, sdk-java-core, sdk-py-core
> Reporter: Brian Hulette
> Assignee: Brian Hulette
> Priority: Major
> Time Spent: 1h 50m
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)