3333import org .apache .drill .exec .server .options .OptionManager ;
3434import org .apache .drill .exec .vector .complex .writer .BaseWriter ;
3535import org .apache .drill .exec .vector .complex .writer .BaseWriter .ComplexWriter ;
36-
36+ @ SuppressWarnings ( "unused" )
3737public class JsonConvertFrom {
3838
3939 private JsonConvertFrom () {}
@@ -55,38 +55,39 @@ public static class ConvertFromJsonNullableInput implements DrillSimpleFunc {
5555 ResultSetLoader rsLoader ;
5656
5757 @ Workspace
58- org .apache .drill .exec .store .easy .json .loader .SingleElementIterator <java .io .InputStream > stream ;
58+ org .apache .drill .exec .store .easy .json .loader .SingleElementIterator <java .io .InputStream > streamIter ;
5959
6060 @ Workspace
6161 org .apache .drill .exec .store .easy .json .loader .JsonLoaderImpl jsonLoader ;
6262
6363 @ Override
6464 public void setup () {
65+ streamIter = new org .apache .drill .exec .store .easy .json .loader .SingleElementIterator <>();
6566 rsLoader .startBatch ();
6667 }
6768
6869 @ Override
6970 public void eval () {
70- if ( in . end == 0 ) {
71- // Return empty map
71+ // If the input is null or empty, return an empty map
72+ if ( in . isSet == 0 || in . start == in . end ) {
7273 return ;
7374 }
7475
7576 java .io .InputStream inputStream = org .apache .drill .exec .vector .complex .fn .DrillBufInputStream .getStream (in .start , in .end , in .buffer );
7677
7778 try {
78- stream .setValue (inputStream );
79+ streamIter .setValue (inputStream );
7980
8081 if (jsonLoader == null ) {
81- jsonLoader = org .apache .drill .exec .expr .fn .impl .conv .JsonConverterUtils .createJsonLoader (rsLoader , options , stream );
82+ jsonLoader = org .apache .drill .exec .expr .fn .impl .conv .JsonConverterUtils .createJsonLoader (rsLoader , options , streamIter );
8283 }
8384
8485 org .apache .drill .exec .physical .resultSet .RowSetLoader rowWriter = rsLoader .writer ();
8586 rowWriter .start ();
8687 if (jsonLoader .parser ().next ()) {
8788 rowWriter .save ();
8889 }
89- inputStream .close ();
90+ // inputStream.close();
9091
9192 } catch (Exception e ) {
9293 throw org .apache .drill .common .exceptions .UserException .dataReadError (e )
@@ -108,7 +109,7 @@ public static class ConvertFromJsonVarcharInput implements DrillSimpleFunc {
108109 ComplexWriter writer ;
109110
110111 @ Workspace
111- org .apache .drill .exec .store .easy .json .loader .SingleElementIterator <java .io .InputStream > stream ;
112+ org .apache .drill .exec .store .easy .json .loader .SingleElementIterator <java .io .InputStream > streamIter ;
112113
113114 @ Inject
114115 OptionManager options ;
@@ -119,25 +120,25 @@ public static class ConvertFromJsonVarcharInput implements DrillSimpleFunc {
119120 @ Workspace
120121 org .apache .drill .exec .store .easy .json .loader .JsonLoaderImpl jsonLoader ;
121122
122-
123123 @ Override
124124 public void setup () {
125+ streamIter = new org .apache .drill .exec .store .easy .json .loader .SingleElementIterator <>();
125126 rsLoader .startBatch ();
126127 }
127128
128129 @ Override
129130 public void eval () {
130- String jsonString = org .apache .drill .exec .expr .fn .impl .StringFunctionHelpers .toStringFromUTF8 (in .start , in .end , in .buffer );
131-
132131 // If the input is null or empty, return an empty map
133- if (jsonString . length () == 0 ) {
132+ if (in . isSet == 0 || in . start == in . end ) {
134133 return ;
135134 }
136135
136+ java .io .InputStream inputStream = org .apache .drill .exec .vector .complex .fn .DrillBufInputStream .getStream (in .start , in .end , in .buffer );
137+
137138 try {
138- stream .setValue (org . apache . drill . exec . expr . fn . impl . conv . JsonConverterUtils . convertStringToInputStream ( jsonString ) );
139+ streamIter .setValue (inputStream );
139140 if (jsonLoader == null ) {
140- jsonLoader = org .apache .drill .exec .expr .fn .impl .conv .JsonConverterUtils .createJsonLoader (rsLoader , options , stream );
141+ jsonLoader = org .apache .drill .exec .expr .fn .impl .conv .JsonConverterUtils .createJsonLoader (rsLoader , options , streamIter );
141142 }
142143 org .apache .drill .exec .physical .resultSet .RowSetLoader rowWriter = rsLoader .writer ();
143144 rowWriter .start ();
0 commit comments