[
https://issues.apache.org/jira/browse/ARROW-1209?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16239258#comment-16239258
]
ASF GitHub Bot commented on ARROW-1209:
---------------------------------------
cpcloud commented on a change in pull request #1026: ARROW-1209: [C++] [WIP]
Support for reading avro from an AvroFileReader
URL: https://github.com/apache/arrow/pull/1026#discussion_r148942080
##########
File path: cpp/src/arrow/adapters/avro/adapter.cc
##########
@@ -0,0 +1,325 @@
+// 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.
+
+#include <cstdint>
+#include <memory>
+#include <string>
+#include <sstream>
+#include <arrow/util/logging.h>
+
+#include "arrow/adapters/avro/adapter.h"
+
+#include "arrow/builder.h"
+#include "arrow/buffer.h"
+#include "arrow/memory_pool.h"
+#include "arrow/status.h"
+#include "arrow/table.h"
+#include "arrow/type.h"
+#include "arrow/type_traits.h"
+#include "arrow/util/bit-util.h"
+#include "arrow/util/macros.h"
+#include "arrow/util/visibility.h"
+
+#include "avro.h"
+
+namespace arrow {
+namespace adapters {
+namespace avro {
+
+class AvroArrowReader::AvroArrowReaderImpl {
+public:
+ Status GenerateAvroSchema(avro_file_reader_t *file_reader,
+ std::shared_ptr<DataType> *out) {
+ auto wschema = avro_file_reader_get_writer_schema(*file_reader);
+ std::shared_ptr<DataType> arrow_schema = get_arrow_type(wschema);
+ // make array builder
+ out = &arrow_schema;
+ return Status::OK();
+ }
+
+ std::shared_ptr<DataType> get_arrow_type(avro_schema_t schema) {
+ avro_schema_t child;
+ size_t size, idx;
+ int64_t length;
+ const char *name;
+
+ auto avro_type = schema->type;
+ switch (avro_type) {
+ case AVRO_BOOLEAN:
+ return boolean();
+ case AVRO_INT32:
+ return int32();
+ case AVRO_INT64:
+ return int64();
+ case AVRO_FLOAT:
+ return float32();
+ case AVRO_DOUBLE:
+ return float64();
+ case AVRO_STRING:
+ return utf8();
+ case AVRO_BYTES:
+ return binary();
+ case AVRO_FIXED: {
+ length = avro_schema_fixed_size(schema);
+ return fixed_size_binary(length);
+ }
+ case AVRO_ARRAY: {
+ auto elem_type = get_arrow_type(avro_schema_array_items(schema));
+ return list(elem_type);
+ }
+
+ case AVRO_MAP: {
+ auto value_type = get_arrow_type(avro_schema_map_values(schema));
+ auto fields = {field("key", utf8()), field("value", value_type)};
+ return list(struct_(fields));
+ }
+
+ case AVRO_UNION: {
+ size = avro_schema_union_size(schema);
+ auto fields = std::vector<std::shared_ptr<Field>>();
+ std::vector<uint8_t> type_codes;
+
+ for (idx = 0; idx < size; idx++) {
+ child = avro_schema_union_branch(schema, idx);
+ auto f = field("_union_" + std::to_string(idx),
+ get_arrow_type(child));
+ fields.push_back(f);
+ type_codes.push_back((uint8_t) idx);
+ };
+ return union_(fields, type_codes);
+ }
+
+ case AVRO_RECORD: {
+ size = avro_schema_record_size(schema);
+ auto fields = std::vector<std::shared_ptr<Field>>();
+ for (idx = 0; idx < size; idx++) {
+ child = avro_schema_record_field_get_by_index(schema, idx);
+ auto elem_type = get_arrow_type(child);
+ name = avro_schema_record_field_name(schema, idx);
+ auto f = field(name, elem_type);
+ fields.insert(fields.end(), f);
+ }
+ return struct_(fields);
+ }
+ }
Review comment:
You'll need a `default:` case here, otherwise you should get a compiler
warning on at least one of the compilers we test against (which will cause a
failure due to compiling with warnings-as-errors).
----------------------------------------------------------------
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]
> [C++] Implement converter between Arrow record batches and Avro records
> -----------------------------------------------------------------------
>
> Key: ARROW-1209
> URL: https://issues.apache.org/jira/browse/ARROW-1209
> Project: Apache Arrow
> Issue Type: New Feature
> Components: C++
> Reporter: Wes McKinney
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.0.0
>
>
> This would be useful for streaming systems that need to consume or produce
> Avro in C/C++
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)