jiangzhx commented on issue #6026:
URL: 
https://github.com/apache/arrow-datafusion/issues/6026#issuecomment-1515828120

   > @jiangzhx if you register a json with an empty array like this
   > 
   > ```
   > {"items": []}
   > ```
   
   I'm afraid we don't have the "capability" to support nulls in JSON reader.
   This is because the specific data type of an empty array [] in JSON format 
cannot be inferred when there is only one row of data.
   
    consider the following JSON string, JSON reader will use 
`infer_json_schema` method to inferred the datatype.
   ```
   {"items": []}
   {"items": [1,2]}
   ```
   
   OR
   
   you can specify the schema to the reader.
   
   ```
   #[tokio::test]
   async fn json_single_nan_array_schema() {
       let ctx = SessionContext::new();
       let path = format!("{TEST_DATA_BASE}/4.json");
       let schema = Schema::new(vec![Field::new(
           "items",
           DataType::List(FieldRef::new(Field::new("item", Int32, true))),
           false,
       )]);
   
       let options = NdJsonReadOptions::default().schema(&schema);
   
       ctx.register_json("single_array_nan", &path, options)
           .await
           .unwrap();
   
       let sql = "SELECT items FROM single_array_nan";
       let dataframe = ctx.sql(sql).await.unwrap();
       let results = dataframe.collect().await.unwrap();
       print_batches(&results);
   }
   ```
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to