@@ -61,14 +61,38 @@ public static void query(ClickHouseHelperClient chc, String query) {
61
61
chc .queryV1 (query );
62
62
}
63
63
}
64
- public static void dropTable (ClickHouseHelperClient chc , String tableName ) {
64
+
65
+ public static OperationMetrics dropTable (ClickHouseHelperClient chc , String tableName ) {
66
+ for (int i = 0 ; i < 5 ; i ++) {
67
+ try {
68
+ OperationMetrics operationMetrics = dropTableLoop (chc , tableName );
69
+ if (operationMetrics != null ) {
70
+ return operationMetrics ;
71
+ }
72
+ } catch (Exception e ) {
73
+ LOGGER .error ("Error while sleeping" , e );
74
+ }
75
+
76
+ try {
77
+ Thread .sleep (30000 );//Sleep for 30 seconds
78
+ } catch (InterruptedException e ) {
79
+ LOGGER .error ("Error while sleeping" , e );
80
+ }
81
+ }
82
+
83
+ return null ;
84
+ }
85
+ private static OperationMetrics dropTableLoop (ClickHouseHelperClient chc , String tableName ) {
65
86
String dropTable = String .format ("DROP TABLE IF EXISTS `%s`" , tableName );
66
87
try {
67
- chc .getClient ().queryRecords (dropTable ).get (CLOUD_TIMEOUT_VALUE , CLOUD_TIMEOUT_UNIT );
88
+ return chc .getClient ().queryRecords (dropTable ).get (CLOUD_TIMEOUT_VALUE , CLOUD_TIMEOUT_UNIT ). getMetrics ( );
68
89
} catch (Exception e ) {
69
90
throw new RuntimeException (e );
70
91
}
71
92
}
93
+
94
+
95
+
72
96
public static OperationMetrics createTable (ClickHouseHelperClient chc , String tableName , String createTableQuery ) {
73
97
LOGGER .info ("Creating table: {}, Query: {}" , tableName , createTableQuery );
74
98
OperationMetrics operationMetrics = createTable (chc , tableName , createTableQuery , new HashMap <>());
@@ -83,18 +107,38 @@ public static OperationMetrics createTable(ClickHouseHelperClient chc, String ta
83
107
}
84
108
85
109
public static OperationMetrics createTable (ClickHouseHelperClient chc , String tableName , String createTableQuery , Map <String , Serializable > clientSettings ) {
110
+ for (int i = 0 ; i < 5 ; i ++) {
111
+ try {
112
+ OperationMetrics operationMetrics = createTableLoop (chc , tableName , createTableQuery , clientSettings );
113
+ if (operationMetrics != null ) {
114
+ return operationMetrics ;
115
+ }
116
+ } catch (Exception e ) {
117
+ LOGGER .error ("Error while sleeping" , e );
118
+ }
119
+
120
+ try {
121
+ Thread .sleep (30000 );//Sleep for 30 seconds
122
+ } catch (InterruptedException e ) {
123
+ LOGGER .error ("Error while sleeping" , e );
124
+ }
125
+ }
126
+
127
+ return null ;
128
+ }
129
+ private static OperationMetrics createTableLoop (ClickHouseHelperClient chc , String tableName , String createTableQuery , Map <String , Serializable > clientSettings ) {
86
130
final String createTableQueryTmp = String .format (createTableQuery , tableName );
87
131
QuerySettings settings = new QuerySettings ();
88
132
for (Map .Entry <String , Serializable > entry : clientSettings .entrySet ()) {
89
133
settings .setOption (entry .getKey (), entry .getValue ());
90
134
}
91
135
try {
92
- Records records = chc .getClient ().queryRecords (createTableQueryTmp , settings ).get (CLOUD_TIMEOUT_VALUE , CLOUD_TIMEOUT_UNIT );
93
- return records .getMetrics ();
136
+ return chc .getClient ().queryRecords (createTableQueryTmp , settings ).get (CLOUD_TIMEOUT_VALUE , CLOUD_TIMEOUT_UNIT ).getMetrics ();
94
137
} catch (Exception e ) {
95
138
throw new RuntimeException (e );
96
139
}
97
140
}
141
+
98
142
public static List <JSONObject > getAllRowsAsJson (ClickHouseHelperClient chc , String tableName ) {
99
143
String query = String .format ("SELECT * FROM `%s`" , tableName );
100
144
QuerySettings querySettings = new QuerySettings ();
0 commit comments