@@ -184,36 +184,48 @@ protected ClickHouseResponse processSqlStatement(ClickHouseSqlStatement stmt) th
184184 }
185185 return ClickHouseResponse .EMPTY ;
186186 } else if (connection .getJdbcConfig ().useLocalFile () && stmt .hasFile ()) {
187- final String file = ClickHouseUtils .unescape (stmt .getFile ());
187+ String file = ClickHouseUtils .unescape (stmt .getFile ());
188+ boolean suffix = file .lastIndexOf ('!' ) == file .length () - 1 ;
189+ if (suffix ) {
190+ file = file .substring (0 , file .length () - 1 );
191+ }
188192 if (stmt .getStatementType () == StatementType .SELECT ) {
189- ClickHouseFile f = ClickHouseFile .of (file );
190- if (f .getFile ().exists ()) {
193+ ClickHouseFile f = ClickHouseFile .of (ClickHouseUtils . getFile ( file ) );
194+ if (! suffix && f .getFile ().exists ()) {
191195 throw SqlExceptionUtils
192196 .clientError (ClickHouseUtils .format ("Output file [%s] already exists!" , f .getFile ()));
193197 }
194198
199+ f = getFile (f , stmt );
195200 final ClickHouseResponseSummary summary = new ClickHouseResponseSummary (null , null );
196- try (ClickHouseResponse response = request .query (stmt .getSQL ()).output (getFile (f , stmt ))
197- .executeAndWait ()) {
201+ try (ClickHouseResponse response = request .query (stmt .getSQL ()).output (f ).executeAndWait ()) {
198202 summary .add (response .getSummary ());
199203 } catch (ClickHouseException e ) {
200204 throw SqlExceptionUtils .handle (e );
201205 }
202206 return ClickHouseSimpleResponse .of (getConfig (),
203207 Arrays .asList (ClickHouseColumn .of ("file" , ClickHouseDataType .String , false ),
204- ClickHouseColumn .of ("rows" , ClickHouseDataType .UInt64 , false ),
208+ ClickHouseColumn .of ("format" , ClickHouseDataType .String , false ),
209+ ClickHouseColumn .of ("compression" , ClickHouseDataType .String , false ),
210+ ClickHouseColumn .of ("level" , ClickHouseDataType .Int32 , false ),
205211 ClickHouseColumn .of ("bytes" , ClickHouseDataType .UInt64 , false )),
206- new Object [][] {
207- { file , summary .getReadRows (), summary .getReadBytes () }
208- }, summary );
212+ new Object [][] { { file , f .getFormat ().name (),
213+ f .hasCompression () ? f .getCompressionAlgorithm ().encoding () : "none" ,
214+ f .getCompressionLevel (), f .getFile ().length () } },
215+ summary );
209216 } else if (stmt .getStatementType () == StatementType .INSERT ) {
210217 final Mutation m = request .write ().query (stmt .getSQL ());
211218 final ClickHouseResponseSummary summary = new ClickHouseResponseSummary (null , null );
212219 try {
213220 for (Path p : ClickHouseUtils .findFiles (file )) {
214221 ClickHouseFile f = ClickHouseFile .of (p .toFile ());
215222 if (!f .getFile ().exists ()) {
216- log .warn ("Skip [%s] as it does not exist" , f );
223+ if (suffix ) {
224+ throw SqlExceptionUtils
225+ .clientError (ClickHouseUtils .format ("File [%s] does not exist!" , f .getFile ()));
226+ } else {
227+ log .warn ("Skip [%s] as it does not exist - perhaps it was just deleted somehow?" , f );
228+ }
217229 } else {
218230 try (ClickHouseResponse response = m .data (getFile (f , stmt )).executeAndWait ()) {
219231 summary .add (response .getSummary ());
@@ -224,7 +236,7 @@ protected ClickHouseResponse processSqlStatement(ClickHouseSqlStatement stmt) th
224236 }
225237 }
226238 }
227- if (summary .getUpdateCount () == 0 ) {
239+ if (suffix && summary .getUpdateCount () == 0 ) {
228240 throw SqlExceptionUtils .clientError ("No file imported: " + file );
229241 }
230242 summary .seal ();
0 commit comments