You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "e1ijah1 (via GitHub)" <gi...@apache.org> on 2023/05/16 10:42:04 UTC

[GitHub] [arrow-datafusion] e1ijah1 opened a new pull request, #6362: [sqllogictest] port tests in avro.rs to sqllogictest

e1ijah1 opened a new pull request, #6362:
URL: https://github.com/apache/arrow-datafusion/pull/6362

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #6299 
   
   # Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   #6195 
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   Port the Rust unit tests from avro.rs, excluding avro_query_multiple_files, to sqllogictest.
   
   # Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   yes.
   
   # Are there any user-facing changes?
   
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #6362: [sqllogictest] port tests in avro.rs to sqllogictest

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #6362:
URL: https://github.com/apache/arrow-datafusion/pull/6362#discussion_r1195007277


##########
datafusion/core/tests/sql/avro.rs:
##########
@@ -1,157 +0,0 @@
-// 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 super::*;
-
-async fn register_alltypes_avro(ctx: &SessionContext) {
-    let testdata = datafusion::test_util::arrow_test_data();
-    ctx.register_avro(
-        "alltypes_plain",
-        &format!("{testdata}/avro/alltypes_plain.avro"),
-        AvroReadOptions::default(),
-    )
-    .await
-    .unwrap();
-}
-
-#[tokio::test]
-async fn avro_query() {
-    let ctx = SessionContext::new();
-    register_alltypes_avro(&ctx).await;
-    // NOTE that string_col is actually a binary column and does not have the UTF8 logical type
-    // so we need an explicit cast
-    let sql = "SELECT id, CAST(string_col AS varchar) FROM alltypes_plain";
-    let actual = execute_to_batches(&ctx, sql).await;
-    let expected = vec![
-        "+----+---------------------------+",
-        "| id | alltypes_plain.string_col |",
-        "+----+---------------------------+",
-        "| 4  | 0                         |",
-        "| 5  | 1                         |",
-        "| 6  | 0                         |",
-        "| 7  | 1                         |",
-        "| 2  | 0                         |",
-        "| 3  | 1                         |",
-        "| 0  | 0                         |",
-        "| 1  | 1                         |",
-        "+----+---------------------------+",
-    ];
-
-    assert_batches_eq!(expected, &actual);
-}
-
-#[tokio::test]
-async fn avro_query_multiple_files() {

Review Comment:
   I see that this test was not ported directly -- since the avro code uses the same codepath as all the other listing tables for handling multiple files it is probably ok. 
   
   However, I think it is important coverage to maintain as the end to end coverage makes sure everything is hooked up correctly. 
   
   I think the issue is there is no way to setup these files using sqllogictest. Perhaps you can add a special sqllogictest test setup (to make the directory with multiple files)  following this model:
   
   https://github.com/apache/arrow-datafusion/blob/b578c5819fc05801f2972dd427fbc13cf4773ea8/datafusion/core/tests/sqllogictests/src/main.rs#L171



-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on pull request #6362: [sqllogictest] port tests in avro.rs to sqllogictest

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #6362:
URL: https://github.com/apache/arrow-datafusion/pull/6362#issuecomment-1553488086

   This PR was failing on CI: https://github.com/apache/arrow-datafusion/actions/runs/5010297388/jobs/8991828477 -- I pushed some fixes for `cargo fmt` and the hash collisions failures. Hopefully the tests pass this time


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb merged pull request #6362: [sqllogictest] port tests in avro.rs to sqllogictest

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #6362:
URL: https://github.com/apache/arrow-datafusion/pull/6362


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on pull request #6362: [sqllogictest] port tests in avro.rs to sqllogictest

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #6362:
URL: https://github.com/apache/arrow-datafusion/pull/6362#issuecomment-1554303581

   Thanks again @e1ijah1 


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #6362: [sqllogictest] port tests in avro.rs to sqllogictest

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #6362:
URL: https://github.com/apache/arrow-datafusion/pull/6362#discussion_r1196971797


##########
datafusion/core/tests/sql/avro.rs:
##########
@@ -1,157 +0,0 @@
-// 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 super::*;
-
-async fn register_alltypes_avro(ctx: &SessionContext) {
-    let testdata = datafusion::test_util::arrow_test_data();
-    ctx.register_avro(
-        "alltypes_plain",
-        &format!("{testdata}/avro/alltypes_plain.avro"),
-        AvroReadOptions::default(),
-    )
-    .await
-    .unwrap();
-}
-
-#[tokio::test]
-async fn avro_query() {
-    let ctx = SessionContext::new();
-    register_alltypes_avro(&ctx).await;
-    // NOTE that string_col is actually a binary column and does not have the UTF8 logical type
-    // so we need an explicit cast
-    let sql = "SELECT id, CAST(string_col AS varchar) FROM alltypes_plain";
-    let actual = execute_to_batches(&ctx, sql).await;
-    let expected = vec![
-        "+----+---------------------------+",
-        "| id | alltypes_plain.string_col |",
-        "+----+---------------------------+",
-        "| 4  | 0                         |",
-        "| 5  | 1                         |",
-        "| 6  | 0                         |",
-        "| 7  | 1                         |",
-        "| 2  | 0                         |",
-        "| 3  | 1                         |",
-        "| 0  | 0                         |",
-        "| 1  | 1                         |",
-        "+----+---------------------------+",
-    ];
-
-    assert_batches_eq!(expected, &actual);
-}
-
-#[tokio::test]
-async fn avro_query_multiple_files() {

Review Comment:
   🤔  I think adding something to `SessionContext` for testing only is likely not the best idea
   
   Maybe we could return the TempDir alongside the `SessionContext` like:
   
   ```rust
   struct TestContext {
     /// Context for running queries
     ctx: SessionContext,
     /// Temporary directory created and cleared at the end of the test
     tmpdir: TempDir
   }
   ```
   And then change
   ```rust
   async fn context_for_test_file(relative_path: &Path) -> SessionContext {
   ```
   
   to 
   ```rust
   async fn context_for_test_file(relative_path: &Path) -> TestContext {
   ```
   



-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] e1ijah1 commented on a diff in pull request #6362: [sqllogictest] port tests in avro.rs to sqllogictest

Posted by "e1ijah1 (via GitHub)" <gi...@apache.org>.
e1ijah1 commented on code in PR #6362:
URL: https://github.com/apache/arrow-datafusion/pull/6362#discussion_r1197334043


##########
datafusion/core/tests/sql/avro.rs:
##########
@@ -1,157 +0,0 @@
-// 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 super::*;
-
-async fn register_alltypes_avro(ctx: &SessionContext) {
-    let testdata = datafusion::test_util::arrow_test_data();
-    ctx.register_avro(
-        "alltypes_plain",
-        &format!("{testdata}/avro/alltypes_plain.avro"),
-        AvroReadOptions::default(),
-    )
-    .await
-    .unwrap();
-}
-
-#[tokio::test]
-async fn avro_query() {
-    let ctx = SessionContext::new();
-    register_alltypes_avro(&ctx).await;
-    // NOTE that string_col is actually a binary column and does not have the UTF8 logical type
-    // so we need an explicit cast
-    let sql = "SELECT id, CAST(string_col AS varchar) FROM alltypes_plain";
-    let actual = execute_to_batches(&ctx, sql).await;
-    let expected = vec![
-        "+----+---------------------------+",
-        "| id | alltypes_plain.string_col |",
-        "+----+---------------------------+",
-        "| 4  | 0                         |",
-        "| 5  | 1                         |",
-        "| 6  | 0                         |",
-        "| 7  | 1                         |",
-        "| 2  | 0                         |",
-        "| 3  | 1                         |",
-        "| 0  | 0                         |",
-        "| 1  | 1                         |",
-        "+----+---------------------------+",
-    ];
-
-    assert_batches_eq!(expected, &actual);
-}
-
-#[tokio::test]
-async fn avro_query_multiple_files() {

Review Comment:
   Thank you for taking the time to review my PR 🙏. I have updated the code. Please take another look.



-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] e1ijah1 commented on a diff in pull request #6362: [sqllogictest] port tests in avro.rs to sqllogictest

Posted by "e1ijah1 (via GitHub)" <gi...@apache.org>.
e1ijah1 commented on code in PR #6362:
URL: https://github.com/apache/arrow-datafusion/pull/6362#discussion_r1196627523


##########
datafusion/core/tests/sql/avro.rs:
##########
@@ -1,157 +0,0 @@
-// 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 super::*;
-
-async fn register_alltypes_avro(ctx: &SessionContext) {
-    let testdata = datafusion::test_util::arrow_test_data();
-    ctx.register_avro(
-        "alltypes_plain",
-        &format!("{testdata}/avro/alltypes_plain.avro"),
-        AvroReadOptions::default(),
-    )
-    .await
-    .unwrap();
-}
-
-#[tokio::test]
-async fn avro_query() {
-    let ctx = SessionContext::new();
-    register_alltypes_avro(&ctx).await;
-    // NOTE that string_col is actually a binary column and does not have the UTF8 logical type
-    // so we need an explicit cast
-    let sql = "SELECT id, CAST(string_col AS varchar) FROM alltypes_plain";
-    let actual = execute_to_batches(&ctx, sql).await;
-    let expected = vec![
-        "+----+---------------------------+",
-        "| id | alltypes_plain.string_col |",
-        "+----+---------------------------+",
-        "| 4  | 0                         |",
-        "| 5  | 1                         |",
-        "| 6  | 0                         |",
-        "| 7  | 1                         |",
-        "| 2  | 0                         |",
-        "| 3  | 1                         |",
-        "| 0  | 0                         |",
-        "| 1  | 1                         |",
-        "+----+---------------------------+",
-    ];
-
-    assert_batches_eq!(expected, &actual);
-}
-
-#[tokio::test]
-async fn avro_query_multiple_files() {

Review Comment:
   Considering that `avro_query_multiple_files` utilizes a temporary directory, could we maintain the temporary directory within `SessionContext` to facilitate the creation of necessary data during the setup phase?



-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #6362: [sqllogictest] port tests in avro.rs to sqllogictest

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #6362:
URL: https://github.com/apache/arrow-datafusion/pull/6362#discussion_r1198180698


##########
datafusion/core/tests/sqllogictests/src/setup.rs:
##########
@@ -29,8 +29,41 @@ use datafusion::{
     test_util,
 };
 use std::sync::Arc;
+use datafusion::prelude::AvroReadOptions;
 
-use crate::utils;
+use crate::{TestContext, utils};
+
+pub async fn register_avro_tables(ctx: &mut TestContext) {
+    register_avro_test_data(ctx).await;
+}
+
+async fn register_avro_test_data(ctx: &mut TestContext) {
+    ctx.enable_testdir();

Review Comment:
   👍  looks good to me -- I think it may even make sense to always create the temp directory but for now making it just for avro looks great.



##########
datafusion/core/tests/sqllogictests/test_files/avro.slt:
##########
@@ -0,0 +1,97 @@
+# 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.
+
+
+statement ok
+CREATE EXTERNAL TABLE alltypes_plain (
+  id  INT NOT NULL,
+  bool_col BOOLEAN NOT NULL,
+  tinyint_col TINYINT NOT NULL,
+  smallint_col SMALLINT NOT NULL,
+  int_col INT NOT NULL,
+  bigint_col BIGINT NOT NULL,
+  float_col FLOAT NOT NULL,
+  double_col DOUBLE NOT NULL,
+  date_string_col BYTEA NOT NULL,
+  string_col VARCHAR NOT NULL,
+  timestamp_col TIMESTAMP NOT NULL,
+)
+STORED AS AVRO
+WITH HEADER ROW
+LOCATION '../../testing/data/avro/alltypes_plain.avro'
+
+statement ok
+CREATE EXTERNAL TABLE single_nan (
+  mycol FLOAT
+)
+STORED AS AVRO
+WITH HEADER ROW
+LOCATION '../../testing/data/avro/single_nan.avro'
+
+# test avro query
+query IT
+SELECT id, CAST(string_col AS varchar) FROM alltypes_plain
+----
+4 0
+5 1
+6 0
+7 1
+2 0
+3 1
+0 0
+1 1
+
+# test avro single nan schema
+query R
+SELECT mycol FROM single_nan
+----
+NULL
+
+# test avro query multi files

Review Comment:
   👍 



-- 
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: github-unsubscribe@arrow.apache.org

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