1010import java .io .File ;
1111import java .io .FileInputStream ;
1212import java .io .FileOutputStream ;
13+ import java .io .FileWriter ;
1314import java .io .ObjectInputStream ;
1415import java .io .ObjectOutputStream ;
1516import java .sql .Connection ;
1617import java .sql .ResultSet ;
1718import java .sql .ResultSetMetaData ;
1819import java .sql .SQLException ;
1920import java .sql .Statement ;
21+ import java .text .SimpleDateFormat ;
2022import java .util .ArrayList ;
23+ import java .util .Date ;
2124import java .util .List ;
2225import java .util .Properties ;
26+ import java .util .UUID ;
27+ import java .util .concurrent .TimeUnit ;
28+ import java .util .logging .Logger ;
2329import javax .annotation .Nullable ;
2430import net .snowflake .client .annotations .DontRunOnGithubActions ;
2531import net .snowflake .client .category .TestTags ;
2632import net .snowflake .client .providers .SimpleResultFormatProvider ;
33+ import org .apache .commons .lang3 .time .StopWatch ;
2734import org .junit .jupiter .api .Disabled ;
2835import org .junit .jupiter .api .Tag ;
2936import org .junit .jupiter .api .Test ;
3441/** SnowflakeResultSetSerializable tests */
3542@ Tag (TestTags .RESULT_SET )
3643public class SnowflakeResultSetSerializableIT extends BaseJDBCTest {
44+ private static Logger logger = Logger .getLogger (HeartbeatAsyncLatestIT .class .getName ());
45+
3746 @ TempDir private File tmpFolder ;
3847
3948 private static boolean developPrint = false ;
@@ -242,6 +251,9 @@ private void testBasicTableHarness(
242251 String originalResultCSVString = null ;
243252 try (Connection connection = init (queryResultFormat )) {
244253 Statement statement = connection .createStatement ();
254+ StopWatch stopwatch = new StopWatch ();
255+ stopwatch .start ();
256+ logger .severe (stopwatch .getTime (TimeUnit .SECONDS ) + " ms: testBasicTableHarness start" );
245257
246258 if (developPrint ) {
247259 System .out .println (
@@ -261,14 +273,44 @@ private void testBasicTableHarness(
261273 statement .execute (
262274 "create or replace table table_basic " + " (int_c int, string_c string(128))" );
263275
276+ logger .severe (
277+ stopwatch .getTime (TimeUnit .SECONDS )
278+ + " ms: testBasicTableHarness before insert into table_basic" );
264279 if (rowCount > 0 ) {
265- statement .execute (
266- "insert into table_basic select "
267- + "seq4(), 'arrow_1234567890arrow_1234567890arrow_1234567890arrow_1234567890'"
268- + " from table(generator(rowcount=>"
269- + rowCount
270- + "))" );
280+ File csvFile = File .createTempFile ("snowflake_data_" , ".csv" );
281+ String randomSuffix = UUID .randomUUID ().toString ().replace ("-" , "" ).substring (0 , 8 );
282+ String tmpStageName = "temp_csv_stage_" + randomSuffix ;
283+ String fileFormatName = "my_csv_format_" + randomSuffix ;
284+ try (FileWriter writer = new FileWriter (csvFile )) {
285+ writer .write ("id,value_column\n " );
286+ for (int i = 1 ; i <= rowCount ; i ++) {
287+ writer .write (
288+ i + ",arrow_1234567890arrow_1234567890arrow_1234567890arrow_1234567890\n " );
289+ }
290+ }
291+ try (Statement stmt = connection .createStatement ()) {
292+ stmt .execute ("CREATE TEMPORARY STAGE " + tmpStageName );
293+ stmt .execute (
294+ "CREATE OR REPLACE FILE FORMAT "
295+ + fileFormatName
296+ + " TYPE = 'CSV' FIELD_DELIMITER = ',' SKIP_HEADER = 1" );
297+ String putCmd =
298+ "PUT file://"
299+ + csvFile .getAbsolutePath ().replace ("\\ " , "/" )
300+ + " @"
301+ + tmpStageName
302+ + " AUTO_COMPRESS=TRUE OVERWRITE=TRUE" ;
303+ stmt .execute (putCmd );
304+ stmt .execute (
305+ "COPY INTO table_basic FROM @" + tmpStageName + " FILE_FORMAT = " + fileFormatName );
306+ stmt .execute ("DROP STAGE IF EXISTS " + tmpStageName );
307+ stmt .execute ("DROP FILE FORMAT IF EXISTS " + fileFormatName );
308+ }
309+ csvFile .delete ();
271310 }
311+ logger .severe (
312+ stopwatch .getTime (TimeUnit .SECONDS )
313+ + " ms: testBasicTableHarness after insert into table_basic" );
272314 }
273315
274316 String sqlSelect = "select * from table_basic " + whereClause ;
@@ -277,16 +319,29 @@ private void testBasicTableHarness(
277319 ? statement .unwrap (SnowflakeStatement .class ).executeAsyncQuery (sqlSelect )
278320 : statement .executeQuery (sqlSelect )) {
279321
322+ logger .severe (
323+ stopwatch .getTime (TimeUnit .SECONDS ) + " ms: testBasicTableHarness after select query" );
280324 fileNameList = serializeResultSet ((SnowflakeResultSet ) rs , maxSizeInBytes , "txt" );
325+ logger .severe (
326+ stopwatch .getTime (TimeUnit .SECONDS )
327+ + " ms: testBasicTableHarness after serializeResultSet" );
281328
282329 originalResultCSVString = generateCSVResult (rs );
330+ logger .severe (
331+ stopwatch .getTime (TimeUnit .SECONDS )
332+ + " ms: testBasicTableHarness after whole testcase" );
283333 }
284334 }
285335
286336 String chunkResultString = deserializeResultSet (fileNameList );
287337 assertEquals (chunkResultString , originalResultCSVString );
288338 }
289339
340+ private String generateRandomSuffix () {
341+ SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMMddHHmmssSSS" );
342+ return sdf .format (new Date ());
343+ }
344+
290345 @ ParameterizedTest
291346 @ ArgumentsSource (SimpleResultFormatProvider .class )
292347 @ DontRunOnGithubActions
0 commit comments