[
https://issues.apache.org/jira/browse/ARROW-1209?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16239250#comment-16239250
]
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_r148941970
##########
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;
Review comment:
This will not work and probably falls under the umbrella of "undefined
behavior" somewhere in the standard. `arrow_schema` is a stack allocated
variable and it will be deallocated upon scope exit which in this case is when
the function returns. That means that `out` will be pointing to an invalid
memory location.
What you want to do is:
```
*out = get_arrow_type(wschema);
```
this operation's behavior is documented here:
http://en.cppreference.com/w/cpp/memory/shared_ptr/operator%3D.
----------------------------------------------------------------
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)