@@ -95,7 +95,6 @@ public class HiveTestUtil {
9595 public static TypedProperties hiveSyncProps ;
9696 public static HiveTestService hiveTestService ;
9797 public static FileSystem fileSystem ;
98- public static QueryBasedDDLExecutor ddlExecutor ;
9998
10099 private static ZooKeeperServer zkServer ;
101100 private static HiveServer2 hiveServer ;
@@ -105,7 +104,7 @@ public class HiveTestUtil {
105104 private static DateTimeFormatter dtfOut ;
106105 private static Set <String > createdTablesSet = new HashSet <>();
107106
108- public static void setUp () throws IOException , InterruptedException , HiveException , MetaException {
107+ public static void setUp () throws Exception {
109108 configuration = new Configuration ();
110109 if (zkServer == null ) {
111110 zkService = new ZookeeperTestService (configuration );
@@ -115,7 +114,9 @@ public static void setUp() throws IOException, InterruptedException, HiveExcepti
115114 hiveTestService = new HiveTestService (configuration );
116115 hiveServer = hiveTestService .start ();
117116 }
118- fileSystem = FileSystem .get (configuration );
117+ if (fileSystem == null ) {
118+ fileSystem = FileSystem .get (configuration );
119+ }
119120
120121 basePath = Files .createTempDirectory ("hivesynctest" + Instant .now ().toEpochMilli ()).toUri ().toString ();
121122
@@ -134,39 +135,46 @@ public static void setUp() throws IOException, InterruptedException, HiveExcepti
134135 hiveSyncConfig = new HiveSyncConfig (hiveSyncProps );
135136
136137 dtfOut = DateTimeFormatter .ofPattern ("yyyy/MM/dd" );
137- ddlExecutor = new HiveQueryDDLExecutor (hiveSyncConfig , fileSystem , getHiveConf ());
138138
139139 clear ();
140140 }
141141
142- public static void clearIncrementalPullSetup (String path1 , String path2 ) throws IOException , HiveException , MetaException {
142+ public static void clearIncrementalPullSetup (String path1 , String path2 ) throws Exception {
143143 fileSystem .delete (new Path (path1 ), true );
144144 if (path2 != null ) {
145145 fileSystem .delete (new Path (path2 ), true );
146146 }
147147 clear ();
148148 }
149149
150- public static void clear () throws IOException , HiveException , MetaException {
150+ public static void clear () throws Exception {
151151 fileSystem .delete (new Path (basePath ), true );
152152 HoodieTableMetaClient .withPropertyBuilder ()
153153 .setTableType (HoodieTableType .COPY_ON_WRITE )
154154 .setTableName (TABLE_NAME )
155155 .setPayloadClass (HoodieAvroPayload .class )
156156 .initTable (configuration , basePath );
157157
158- for (String tableName : createdTablesSet ) {
159- ddlExecutor .runSQL ("drop table if exists " + tableName );
158+ try (QueryBasedDDLExecutor ddlExecutor = getQueryBasedDDLExecutor ()) {
159+ for (String tableName : createdTablesSet ) {
160+ ddlExecutor .runSQL ("drop table if exists " + tableName );
161+ }
162+ createdTablesSet .clear ();
163+ ddlExecutor .runSQL ("drop database if exists " + DB_NAME + " cascade" );
160164 }
161- createdTablesSet .clear ();
162- ddlExecutor .runSQL ("drop database if exists " + DB_NAME + " cascade" );
165+ }
166+
167+ public static QueryBasedDDLExecutor getQueryBasedDDLExecutor () throws HiveException , MetaException {
168+ HiveConf hiveConf = new HiveConf (configuration , HiveConf .class );
169+ hiveConf .addResource (fileSystem .getConf ());
170+ return new HiveQueryDDLExecutor (hiveSyncConfig , fileSystem , hiveConf );
163171 }
164172
165173 public static HiveConf getHiveConf () {
166174 return hiveServer .getHiveConf ();
167175 }
168176
169- public static void shutdown () {
177+ public static void shutdown () throws Exception {
170178 if (hiveServer != null ) {
171179 hiveServer .stop ();
172180 }
0 commit comments