Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
25 changed files
with
1,151 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.hudi.aws.sync; | ||
|
||
import org.apache.hudi.common.config.TypedProperties; | ||
import org.apache.hudi.common.fs.FSUtils; | ||
import org.apache.hudi.hive.HiveSyncConfig; | ||
import org.apache.hudi.hive.HiveSyncTool; | ||
|
||
import com.beust.jcommander.JCommander; | ||
import jdk.jfr.Experimental; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.FileSystem; | ||
import org.apache.hadoop.hive.conf.HiveConf; | ||
|
||
/** | ||
* Currently Experimental. Utility class that implements syncing a Hudi Table with the | ||
* AWS Glue Data Catalog (https://docs.aws.amazon.com/glue/latest/dg/populate-data-catalog.html) | ||
* to enable querying via Glue ETLs, Athena etc. | ||
* | ||
* Extends HiveSyncTool since most logic is similar to Hive syncing, | ||
* expect using a different client {@link AWSGlueCatalogSyncClient} that implements | ||
* the necessary functionality using Glue APIs. | ||
*/ | ||
@Experimental | ||
public class AwsGlueCatalogSyncTool extends HiveSyncTool { | ||
|
||
public AwsGlueCatalogSyncTool(TypedProperties props, Configuration conf, FileSystem fs) { | ||
super(props, new HiveConf(conf, HiveConf.class), fs); | ||
} | ||
|
||
private AwsGlueCatalogSyncTool(HiveSyncConfig hiveSyncConfig, HiveConf hiveConf, FileSystem fs) { | ||
super(hiveSyncConfig, hiveConf, fs); | ||
} | ||
|
||
@Override | ||
protected void initClient(HiveSyncConfig hiveSyncConfig, HiveConf hiveConf) { | ||
hoodieHiveClient = new AWSGlueCatalogSyncClient(hiveSyncConfig, hiveConf, fs); | ||
} | ||
|
||
public static void main(String[] args) { | ||
// parse the params | ||
final HiveSyncConfig cfg = new HiveSyncConfig(); | ||
JCommander cmd = new JCommander(cfg, null, args); | ||
if (cfg.help || args.length == 0) { | ||
cmd.usage(); | ||
System.exit(1); | ||
} | ||
FileSystem fs = FSUtils.getFs(cfg.basePath, new Configuration()); | ||
HiveConf hiveConf = new HiveConf(); | ||
hiveConf.addResource(fs.getConf()); | ||
new AwsGlueCatalogSyncTool(cfg, hiveConf, fs).syncHoodieTable(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.hudi.aws.sync; | ||
|
||
import org.apache.hudi.hive.HoodieHiveSyncException; | ||
|
||
public class HoodieGlueSyncException extends HoodieHiveSyncException { | ||
|
||
public HoodieGlueSyncException(String message) { | ||
super(message); | ||
} | ||
|
||
public HoodieGlueSyncException(String message, Throwable t) { | ||
super(message, t); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.hudi.aws.utils; | ||
|
||
public final class S3Utils { | ||
|
||
public static String s3aToS3(String s3aUrl) { | ||
return s3aUrl.replaceFirst("(?i)^s3a://", "s3://"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.hudi.common.util; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public class MapUtils { | ||
|
||
public static boolean isNullOrEmpty(Map<?, ?> m) { | ||
return Objects.isNull(m) || m.isEmpty(); | ||
} | ||
|
||
public static boolean nonEmpty(Map<?, ?> m) { | ||
return !isNullOrEmpty(m); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.hudi.common.util; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static org.apache.hudi.common.util.CollectionUtils.batches; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
class TestCollectionUtils { | ||
|
||
@Test | ||
void getBatchesFromList() { | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
batches(Collections.emptyList(), -1); | ||
}); | ||
|
||
assertThrows(IllegalArgumentException.class, () -> { | ||
batches(Collections.emptyList(), 0); | ||
}); | ||
|
||
assertEquals(Collections.emptyList(), batches(Collections.emptyList(), 1)); | ||
|
||
List<List<Integer>> intsBatches1 = batches(Arrays.asList(1, 2, 3, 4, 5, 6), 3); | ||
assertEquals(2, intsBatches1.size()); | ||
assertEquals(Arrays.asList(1, 2, 3), intsBatches1.get(0)); | ||
assertEquals(Arrays.asList(4, 5, 6), intsBatches1.get(1)); | ||
|
||
List<List<Integer>> intsBatches2 = batches(Arrays.asList(1, 2, 3, 4, 5, 6), 5); | ||
assertEquals(2, intsBatches2.size()); | ||
assertEquals(Arrays.asList(1, 2, 3, 4, 5), intsBatches2.get(0)); | ||
assertEquals(Collections.singletonList(6), intsBatches2.get(1)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.