R-JunmingChen commented on code in PR #34586:
URL: https://github.com/apache/arrow/pull/34586#discussion_r1162900658


##########
python/pyarrow/tests/test_dataset.py:
##########
@@ -3172,6 +3202,58 @@ def test_csv_fragment_options(tempdir, dataset_reader):
     assert result.equals(
         pa.table({'col0': pa.array(['foo', 'spam', 'MYNULL'])}))
 
[email protected]
+def test_json_format(tempdir, dataset_reader):
+    table = pa.table({'a': pa.array([1, 2, 3], type="int64"),
+                      'b': pa.array([.1, .2, .3], type="float64")})
+
+    path = str(tempdir / 'test.json')
+    out = table.to_pandas().to_json(orient='records')[1:-1].replace('},{', 
'}\n{')
+    with open(path, 'w') as f:
+        f.write(out)
+
+    dataset = ds.dataset(path, format=ds.JsonFileFormat())
+    result = dataset_reader.to_table(dataset)
+    assert result.equals(table)
+
+    assert_dataset_fragment_convenience_methods(dataset)
+
+    dataset = ds.dataset(path, format='json')
+    result = dataset_reader.to_table(dataset)
+    assert result.equals(table)
+
+def test_json_format_options(tempdir, dataset_reader):
+    table = pa.table({'a': pa.array([1, 2, 3], type="int64"),
+                      'b': pa.array([.1, .2, .3], type="float64")})
+
+    path = str(tempdir / 'test.json')
+    out = table.to_pandas().to_json(orient='records')[1:-1].replace('},{', 
'}\n{')
+    with open(path, 'w') as f:
+        f.write(out)
+    
+    dataset = ds.dataset(path, format=ds.JsonFileFormat(
+        read_options=pa.json.ReadOptions(block_size=64)))

Review Comment:
   Hi, It seems that `newlines_in_values`  doesn't work. I fristly test it with 
JSON Datasets of my PR version and it fails to work then I test it with 
pyarrow.json of release version, it doesn't work too.
    
   I use the following code to read json file
   ```
   import pyarrow.json as pj
   
json_f=pj.read_json("test.json",parse_options=pj.ParseOptions(newlines_in_values=False))
   
json_t=pj.read_json("test.json",parse_options=pj.ParseOptions(newlines_in_values=True))
   ```
   
   Here is the file content of test.json
   ```
   
   {
       "name"
   
       :
       12312
       ,
       "b"
       :
       "test\\n"
   }
   
   {"name":123
   
   ,
   
   "b":
   "\n89\n"}
   
   {"name":123123
   
   }
   
   
   
   ```
   However, the value of `json_f` and `json_t` are the same.
   ```
   pyarrow.Table
   name: int64
   b: string
   ----
   name: [[12312,123,123123]]
   b: [["test\n","
   89
   ",null]]
   ```



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