You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by GitBox <gi...@apache.org> on 2022/09/13 12:22:59 UTC

[GitHub] [avro] martin-g commented on a diff in pull request #1850: AVRO-3591: start with commons schemas

martin-g commented on code in PR #1850:
URL: https://github.com/apache/avro/pull/1850#discussion_r969550452


##########
lang/rust/avro/tests/shared.rs:
##########
@@ -0,0 +1,84 @@
+// 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.
+
+use apache_avro::{types::Value, Codec, Reader, Schema, Writer};
+use std::{
+    fs::{DirEntry, File, ReadDir},
+    io::{BufReader, Error},
+    path::Path,
+    slice::Iter,
+};
+
+const ROOT_DIRECTORY: &str = "../../../share/test/data/schemas";
+
+#[test]
+fn test_schema() {
+    let directory: ReadDir = scan_shared_folder();
+    directory.for_each(|f: Result<DirEntry, Error>| {
+        let e: DirEntry = match f {
+            Err(error) => panic!("Can't get file {:?}", error.to_string()),
+            Ok(entry) => entry,
+        };
+        log::warn!("{:?}", e.file_name());
+        let sub_folder = ROOT_DIRECTORY.to_owned() + "/" + e.file_name().to_str().unwrap();
+
+        test_folder(sub_folder.as_str());
+    });
+}
+
+fn test_folder(folder: &str) {
+    let file_name = folder.to_owned() + "/schema.json";
+    let content = std::fs::read_to_string(file_name).expect("Unable to find schema.jon file");
+
+    let schema: Schema = Schema::parse_str(content.as_str()).expect("Can't read schema");
+
+    let data_file_name = folder.to_owned() + "/data.avro";
+    let data_path: &Path = Path::new(data_file_name.as_str());
+    if !data_path.exists() {
+        log::warn!("data file does not exist");
+    } else {
+        let file: File = File::open(data_path).expect("Can't open data.avro");
+        let reader =
+            Reader::with_schema(&schema, BufReader::new(&file)).expect("Can't read data.avro");
+
+        let mut writer = Writer::with_codec(&schema, Vec::new(), Codec::Null);
+
+        let mut records: Vec<Value> = vec![];
+
+        for r in reader {
+            let record: Value = r.expect("Error on reading");
+            writer.append(record.clone()).expect("Error on write item");
+            records.push(record);
+        }
+
+        writer.flush().expect("Error on flush");
+        let bytes: Vec<u8> = writer.into_inner().unwrap();
+        let reader_bis =
+            Reader::with_schema(&schema, &bytes[..]).expect("Can't read fflushed vector");

Review Comment:
   ```suggestion
               Reader::with_schema(&schema, &bytes[..]).expect("Can't read flushed vector");
   ```



##########
lang/rust/avro/tests/shared.rs:
##########
@@ -0,0 +1,84 @@
+// 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.
+
+use apache_avro::{types::Value, Codec, Reader, Schema, Writer};
+use std::{
+    fs::{DirEntry, File, ReadDir},
+    io::{BufReader, Error},
+    path::Path,
+    slice::Iter,
+};
+
+const ROOT_DIRECTORY: &str = "../../../share/test/data/schemas";
+
+#[test]
+fn test_schema() {
+    let directory: ReadDir = scan_shared_folder();
+    directory.for_each(|f: Result<DirEntry, Error>| {
+        let e: DirEntry = match f {
+            Err(error) => panic!("Can't get file {:?}", error.to_string()),

Review Comment:
   Do you need `.to_string()` here ? I guess the error has either `Display` or `Debug` implementation



-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org