Skip to content

Commit 10e1c04

Browse files
b41shyoungsofun
andauthored
fix: display nested geo values (#734)
* fix display nested geo values * fix --------- Co-authored-by: Yang Xiufeng <yangxiufeng.c@gmail.com>
1 parent 2a37269 commit 10e1c04

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

cli/tests/00-base.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ NULL "{""k1"":""v1"",""k2"":""v2""}" (2,NULL)
3737
1 NULL 1 ab
3838
NULL v1 2 NULL
3939
"{""k1"":""v1"",""k2"":""v2""}" [6162,78797A] "([1,2],""2024-04-10"")"
40+
"[{""type"": ""Point"", ""coordinates"": [-122.35,37.55]}]" "[{""type"": ""LineString"", ""coordinates"": [[0.75,0.75],[-10,20]]}]"
4041
bye

cli/tests/00-base.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ select a[1], b['k1'], c:x, c:y from test_nested;
6464

6565
select {'k1':'v1','k2':'v2'}, [to_binary('ab'), to_binary('xyz')], (parse_json('[1,2]'), to_date('2024-04-10'));
6666

67+
set geometry_output_format='GEOJSON';
68+
select [to_geometry('POINT(-122.35 37.55)')], [st_geographyfromewkt('LINESTRING(0.75 0.75, -10 20)')];
69+
6770
select 'bye';
6871
drop table test;
6972
drop table test_decimal;

sql/src/value/string_decoder.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -354,26 +354,28 @@ impl ValueDecoder {
354354

355355
fn read_geometry<R: AsRef<[u8]>>(&self, reader: &mut Cursor<R>) -> Result<Value> {
356356
let mut buf = Vec::new();
357-
if reader.read_quoted_text(&mut buf, b'"').is_err() {
358-
if let Ok(val) = self.read_json(reader) {
359-
return Ok(Value::Variant(val));
360-
}
361-
reader.read_quoted_text(&mut buf, b'\'')?;
357+
if reader.read_quoted_text(&mut buf, b'"').is_ok()
358+
|| reader.read_quoted_text(&mut buf, b'\'').is_ok()
359+
{
360+
Ok(Value::Geometry(unsafe { String::from_utf8_unchecked(buf) }))
361+
} else {
362+
let val = self.read_json(reader)?;
363+
Ok(Value::Geometry(val))
362364
}
363-
Ok(Value::Geometry(unsafe { String::from_utf8_unchecked(buf) }))
364365
}
365366

366367
fn read_geography<R: AsRef<[u8]>>(&self, reader: &mut Cursor<R>) -> Result<Value> {
367368
let mut buf = Vec::new();
368-
if reader.read_quoted_text(&mut buf, b'"').is_err() {
369-
if let Ok(val) = self.read_json(reader) {
370-
return Ok(Value::Variant(val));
371-
}
372-
reader.read_quoted_text(&mut buf, b'\'')?;
369+
if reader.read_quoted_text(&mut buf, b'"').is_ok()
370+
|| reader.read_quoted_text(&mut buf, b'\'').is_ok()
371+
{
372+
Ok(Value::Geography(unsafe {
373+
String::from_utf8_unchecked(buf)
374+
}))
375+
} else {
376+
let val = self.read_json(reader)?;
377+
Ok(Value::Geography(val))
373378
}
374-
Ok(Value::Geography(unsafe {
375-
String::from_utf8_unchecked(buf)
376-
}))
377379
}
378380

379381
fn read_nullable<R: AsRef<[u8]>>(

0 commit comments

Comments
 (0)