Skip to content

Invalid argument error: the data type binary has no natural order #7343

Closed

Description

@JayjeetAtGithub

Describe the bug

On running the query below on the Clickbench multi file dataset,

SELECT "SearchPhrase" FROM hits WHERE "SearchPhrase" <> '' ORDER BY to_timestamp_seconds("EventTime"), "SearchPhrase" LIMIT 10;

we get this error,

Arrow error: Invalid argument error: The data type type Binary has no natural order

To Reproduce

Download the data using,

 ./benchmarks/bench.sh data clickbench_partitioned

A hits_multi directory with the parquet files will be created.

Execute the above queries,

datafusion-cli -c "CREATE EXTERNAL TABLE hits STORED AS PARQUET LOCATION 'hits_multi';" "{query}"

Expected behavior

The queries should run successfully without erroring.

Additional context

Datafusion 29.0.0

Activity

  1. alamb commented on Aug 21, 2023

    @alamb
    Contributor

    This looks similar to #7039 which @jonahgao fixed by adding a coercion from binary --> UTF8 for comparison. I think we could do something similar here.

  2. alamb commented on Aug 21, 2023

    @alamb
    Contributor

    Marking as a good first issue as there is a reproducer and I think the fix should be relatively straightforward

  3. tustvold commented on Aug 21, 2023

    @tustvold
    Contributor

    This may be fixed in the next arrow release, which adds Binary support to lexsort

  4. yjshen commented on Aug 27, 2023

    @yjshen
    Member

    A slightly simpler way to reproduce without the need for datafusion-cli:

    #[tokio::test]
    async fn binary_order() -> Result<()> {
        let schema = Arc::new(Schema::new(vec![
            Field::new("a", DataType::Binary, false),
            Field::new("b", DataType::Int32, false),
        ]));
        let batch = RecordBatch::try_new(
            schema.clone(),
            vec![Arc::new(BinaryArray::from(vec![
                "a".as_bytes(),
                "b".as_bytes(),
                "c".as_bytes(),
            ])),
            Arc::new(Int32Array::from(vec![1, 2, 3]))],
        )?;
    
        let ctx = SessionContext::new();
        ctx.register_batch("aa", batch)?;
        let result = ctx.sql("select a from aa where a <> '' order by b, a").await?;
        let result = result.collect().await?;
        let expected = vec![
            "+----+",
            "| a  |",
            "+----+",
            "| 61 |",
            "| 62 |",
            "| 63 |",
            "+----+",
        ];
        assert_batches_eq!(expected, &result);
        Ok(())
    }
  5. alamb commented on Oct 16, 2023

    @alamb
    Contributor

    I have verified that this now works in datafusion 34. Tests added in #7839

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions