Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
Add decimal test
Browse files Browse the repository at this point in the history
  • Loading branch information
nseekhao committed Dec 12, 2022
1 parent 27b3264 commit 7af8895
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 16 additions & 2 deletions tests/roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use datafusion_substrait::producer;
mod tests {

use crate::{consumer::from_substrait_plan, producer::to_substrait_plan};
use datafusion::arrow::datatypes::{DataType, Field, Schema};
use datafusion::error::Result;
use datafusion::prelude::*;
use substrait::protobuf::extensions::simple_extension_declaration::MappingType;
Expand Down Expand Up @@ -73,6 +74,11 @@ mod tests {
roundtrip("SELECT a, c, avg(b) FROM data GROUP BY a, c").await
}

#[tokio::test]
async fn decimal_literal() -> Result<()> {
roundtrip("SELECT * FROM data WHERE b > 2.5").await
}

#[tokio::test]
async fn simple_distinct() -> Result<()> {
test_alias(
Expand Down Expand Up @@ -156,7 +162,7 @@ mod tests {
)
.await
}

#[tokio::test]
async fn roundtrip_left_join() -> Result<()> {
roundtrip("SELECT data.a FROM data LEFT JOIN data2 ON data.a = data2.a").await
Expand Down Expand Up @@ -261,7 +267,15 @@ mod tests {

async fn create_context() -> Result<SessionContext> {
let ctx = SessionContext::new();
ctx.register_csv("data", "tests/testdata/data.csv", CsvReadOptions::new())
let mut explicit_options = CsvReadOptions::new();
let schema = Schema::new(vec![
Field::new("a", DataType::Int64, true),
Field::new("b", DataType::Decimal128(5, 2), true),
Field::new("c", DataType::Date32, true),
Field::new("d", DataType::Boolean, true),
]);
explicit_options.schema = Some(&schema);
ctx.register_csv("data", "tests/testdata/data.csv", explicit_options)
.await?;
ctx.register_csv("data2", "tests/testdata/data.csv", CsvReadOptions::new())
.await?;
Expand Down
4 changes: 2 additions & 2 deletions tests/testdata/data.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
a,b,c,d
1,2,2020-01-01,false
3,4,2020-01-01,true
1,2.0,2020-01-01,false
3,4.5,2020-01-01,true

0 comments on commit 7af8895

Please sign in to comment.