@@ -184,36 +184,48 @@ protected ClickHouseResponse processSqlStatement(ClickHouseSqlStatement stmt) th
184
184
}
185
185
return ClickHouseResponse .EMPTY ;
186
186
} 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
+ }
188
192
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 ()) {
191
195
throw SqlExceptionUtils
192
196
.clientError (ClickHouseUtils .format ("Output file [%s] already exists!" , f .getFile ()));
193
197
}
194
198
199
+ f = getFile (f , stmt );
195
200
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 ()) {
198
202
summary .add (response .getSummary ());
199
203
} catch (ClickHouseException e ) {
200
204
throw SqlExceptionUtils .handle (e );
201
205
}
202
206
return ClickHouseSimpleResponse .of (getConfig (),
203
207
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 ),
205
211
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 );
209
216
} else if (stmt .getStatementType () == StatementType .INSERT ) {
210
217
final Mutation m = request .write ().query (stmt .getSQL ());
211
218
final ClickHouseResponseSummary summary = new ClickHouseResponseSummary (null , null );
212
219
try {
213
220
for (Path p : ClickHouseUtils .findFiles (file )) {
214
221
ClickHouseFile f = ClickHouseFile .of (p .toFile ());
215
222
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
+ }
217
229
} else {
218
230
try (ClickHouseResponse response = m .data (getFile (f , stmt )).executeAndWait ()) {
219
231
summary .add (response .getSummary ());
@@ -224,7 +236,7 @@ protected ClickHouseResponse processSqlStatement(ClickHouseSqlStatement stmt) th
224
236
}
225
237
}
226
238
}
227
- if (summary .getUpdateCount () == 0 ) {
239
+ if (suffix && summary .getUpdateCount () == 0 ) {
228
240
throw SqlExceptionUtils .clientError ("No file imported: " + file );
229
241
}
230
242
summary .seal ();
0 commit comments