[HUDI-357] Refactor hudi-cli based on new comment and code style rules (#1051)
This commit is contained in:
committed by
vinoth chandar
parent
b65a897856
commit
75132c139f
@@ -25,6 +25,9 @@ import org.apache.hudi.common.table.HoodieTableMetaClient;
|
||||
import org.apache.hudi.common.util.ConsistencyGuardConfig;
|
||||
import org.apache.hudi.common.util.FSUtils;
|
||||
|
||||
/**
|
||||
* This class is responsible to load table metadata and hoodie related configs.
|
||||
*/
|
||||
public class HoodieCLI {
|
||||
|
||||
public static Configuration conf;
|
||||
@@ -35,6 +38,9 @@ public class HoodieCLI {
|
||||
public static HoodieTableMetaClient tableMetadata;
|
||||
public static HoodieTableMetaClient syncTableMetadata;
|
||||
|
||||
/**
|
||||
* Enum for CLI state.
|
||||
*/
|
||||
public enum CLIState {
|
||||
INIT, DATASET, SYNC
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ import org.springframework.core.annotation.Order;
|
||||
import org.springframework.shell.plugin.support.DefaultHistoryFileNameProvider;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* CLI history file provider.
|
||||
*/
|
||||
@Component
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
public class HoodieHistoryFileNameProvider extends DefaultHistoryFileNameProvider {
|
||||
|
||||
@@ -25,12 +25,12 @@ import java.util.function.Function;
|
||||
import org.apache.hudi.common.util.Option;
|
||||
|
||||
/**
|
||||
* Helper class to render table for hoodie-cli
|
||||
* Helper class to render table for hoodie-cli.
|
||||
*/
|
||||
public class HoodiePrintHelper {
|
||||
|
||||
/**
|
||||
* Print header and raw rows
|
||||
* Print header and raw rows.
|
||||
*
|
||||
* @param header Header
|
||||
* @param rows Raw Rows
|
||||
@@ -41,7 +41,7 @@ public class HoodiePrintHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize Table to printable string
|
||||
* Serialize Table to printable string.
|
||||
*
|
||||
* @param rowHeader Row Header
|
||||
* @param fieldNameToConverterMap Field Specific Converters
|
||||
@@ -71,7 +71,7 @@ public class HoodiePrintHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render rows in Table
|
||||
* Render rows in Table.
|
||||
*
|
||||
* @param buffer Table
|
||||
* @return output
|
||||
@@ -86,7 +86,7 @@ public class HoodiePrintHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render only header of the table
|
||||
* Render only header of the table.
|
||||
*
|
||||
* @param header Table Header
|
||||
* @return output
|
||||
@@ -98,7 +98,7 @@ public class HoodiePrintHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Print Text table
|
||||
* Print Text table.
|
||||
*
|
||||
* @param headers Headers
|
||||
* @param data Table
|
||||
|
||||
@@ -23,6 +23,9 @@ import org.springframework.core.annotation.Order;
|
||||
import org.springframework.shell.plugin.support.DefaultPromptProvider;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* This class deals with displaying prompt on CLI based on the state.
|
||||
*/
|
||||
@Component
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
public class HoodiePrompt extends DefaultPromptProvider {
|
||||
|
||||
@@ -24,6 +24,9 @@ import org.springframework.shell.plugin.support.DefaultBannerProvider;
|
||||
import org.springframework.shell.support.util.OsUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* This class is responsible to print the splash screen at the start of the application.
|
||||
*/
|
||||
@Component
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
public class HoodieSplashScreen extends DefaultBannerProvider {
|
||||
|
||||
@@ -21,11 +21,11 @@ package org.apache.hudi.cli;
|
||||
import java.io.IOException;
|
||||
import org.springframework.shell.Bootstrap;
|
||||
|
||||
/**
|
||||
* Main class that delegates to Spring Shell's Bootstrap class in order to simplify debugging inside an IDE.
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
/**
|
||||
* Main class that delegates to Spring Shell's Bootstrap class in order to simplify debugging inside an IDE
|
||||
*/
|
||||
public static void main(String[] args) throws IOException {
|
||||
System.out.println("Main called");
|
||||
new HoodieSplashScreen();
|
||||
|
||||
@@ -63,7 +63,7 @@ public class Table implements Iterable<List<String>> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Main API to add row to the table
|
||||
* Main API to add row to the table.
|
||||
*
|
||||
* @param row Row
|
||||
*/
|
||||
@@ -82,7 +82,7 @@ public class Table implements Iterable<List<String>> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all rows
|
||||
* Add all rows.
|
||||
*
|
||||
* @param rows Rows to be aded
|
||||
* @return
|
||||
@@ -93,7 +93,7 @@ public class Table implements Iterable<List<String>> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all rows
|
||||
* Add all rows.
|
||||
*
|
||||
* @param rows Rows to be added
|
||||
* @return
|
||||
@@ -104,7 +104,7 @@ public class Table implements Iterable<List<String>> {
|
||||
}
|
||||
|
||||
/**
|
||||
* API to let the table know writing is over and reading is going to start
|
||||
* API to let the table know writing is over and reading is going to start.
|
||||
*/
|
||||
public Table flip() {
|
||||
this.finishedAdding = true;
|
||||
@@ -113,7 +113,7 @@ public class Table implements Iterable<List<String>> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorting of rows by a specified field
|
||||
* Sorting of rows by a specified field.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Header for the table to be rendered
|
||||
* Header for the table to be rendered.
|
||||
*/
|
||||
public class TableHeader {
|
||||
|
||||
@@ -30,7 +30,7 @@ public class TableHeader {
|
||||
private final List<String> fieldNames = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Add a field (column) to table
|
||||
* Add a field (column) to table.
|
||||
*
|
||||
* @param fieldName field Name
|
||||
*/
|
||||
@@ -40,14 +40,14 @@ public class TableHeader {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all field names
|
||||
* Get all field names.
|
||||
*/
|
||||
public List<String> getFieldNames() {
|
||||
return fieldNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Index of the field in the table
|
||||
* Index of the field in the table.
|
||||
*
|
||||
* @param fieldName Field Name
|
||||
*/
|
||||
@@ -56,14 +56,14 @@ public class TableHeader {
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup field by offset
|
||||
* Lookup field by offset.
|
||||
*/
|
||||
public String get(int index) {
|
||||
return fieldNames.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of fields in the table
|
||||
* Get number of fields in the table.
|
||||
*/
|
||||
public int getNumFields() {
|
||||
return fieldNames.size();
|
||||
|
||||
@@ -45,6 +45,9 @@ import org.springframework.shell.core.annotation.CliCommand;
|
||||
import org.springframework.shell.core.annotation.CliOption;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* CLI command to display archived commits and stats if available.
|
||||
*/
|
||||
@Component
|
||||
public class ArchivedCommitsCommand implements CommandMarker {
|
||||
|
||||
|
||||
@@ -39,6 +39,9 @@ import org.springframework.shell.core.annotation.CliCommand;
|
||||
import org.springframework.shell.core.annotation.CliOption;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* CLI command to show cleans options.
|
||||
*/
|
||||
@Component
|
||||
public class CleansCommand implements CommandMarker {
|
||||
|
||||
|
||||
@@ -44,6 +44,9 @@ import org.springframework.shell.core.annotation.CliCommand;
|
||||
import org.springframework.shell.core.annotation.CliOption;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* CLI command to display commits options.
|
||||
*/
|
||||
@Component
|
||||
public class CommitsCommand implements CommandMarker {
|
||||
|
||||
|
||||
@@ -59,6 +59,9 @@ import org.springframework.shell.core.annotation.CliCommand;
|
||||
import org.springframework.shell.core.annotation.CliOption;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* CLI command to display compaction related options.
|
||||
*/
|
||||
@Component
|
||||
public class CompactionCommand implements CommandMarker {
|
||||
|
||||
|
||||
@@ -35,6 +35,9 @@ import org.springframework.shell.core.annotation.CliCommand;
|
||||
import org.springframework.shell.core.annotation.CliOption;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* CLI command to display hudi dataset options.
|
||||
*/
|
||||
@Component
|
||||
public class DatasetsCommand implements CommandMarker {
|
||||
|
||||
@@ -67,7 +70,7 @@ public class DatasetsCommand implements CommandMarker {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Hoodie Table if it does not exist
|
||||
* Create a Hoodie Table if it does not exist.
|
||||
*
|
||||
* @param path Base Path
|
||||
* @param name Hoodie Table Name
|
||||
@@ -113,7 +116,7 @@ public class DatasetsCommand implements CommandMarker {
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes table properties
|
||||
* Describes table properties.
|
||||
*/
|
||||
@CliCommand(value = "desc", help = "Describle Hoodie Table properties")
|
||||
public String descTable() {
|
||||
|
||||
@@ -47,6 +47,9 @@ import org.springframework.shell.core.annotation.CliCommand;
|
||||
import org.springframework.shell.core.annotation.CliOption;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* CLI command to display file system options.
|
||||
*/
|
||||
@Component
|
||||
public class FileSystemViewCommand implements CommandMarker {
|
||||
|
||||
@@ -206,7 +209,7 @@ public class FileSystemViewCommand implements CommandMarker {
|
||||
}
|
||||
|
||||
/**
|
||||
* Build File System View
|
||||
* Build File System View.
|
||||
*
|
||||
* @param globRegex Path Regex
|
||||
* @param maxInstant Max Instants to be used for displaying file-instants
|
||||
|
||||
@@ -33,6 +33,9 @@ import org.springframework.shell.core.annotation.CliOption;
|
||||
import org.springframework.stereotype.Component;
|
||||
import scala.collection.JavaConverters;
|
||||
|
||||
/**
|
||||
* CLI command for importing parquet dataset to hudi dataset.
|
||||
*/
|
||||
@Component
|
||||
public class HDFSParquetImportCommand implements CommandMarker {
|
||||
|
||||
|
||||
@@ -59,6 +59,9 @@ import org.springframework.stereotype.Component;
|
||||
import scala.Tuple2;
|
||||
import scala.Tuple3;
|
||||
|
||||
/**
|
||||
* CLI command to display log file options.
|
||||
*/
|
||||
@Component
|
||||
public class HoodieLogFileCommand implements CommandMarker {
|
||||
|
||||
|
||||
@@ -32,6 +32,9 @@ import org.springframework.shell.core.annotation.CliCommand;
|
||||
import org.springframework.shell.core.annotation.CliOption;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* CLI command to display sync options.
|
||||
*/
|
||||
@Component
|
||||
public class HoodieSyncCommand implements CommandMarker {
|
||||
|
||||
|
||||
@@ -34,6 +34,9 @@ import org.springframework.shell.core.annotation.CliCommand;
|
||||
import org.springframework.shell.core.annotation.CliOption;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* CLI command to display and trigger repair options.
|
||||
*/
|
||||
@Component
|
||||
public class RepairsCommand implements CommandMarker {
|
||||
|
||||
|
||||
@@ -42,6 +42,9 @@ import org.springframework.shell.core.annotation.CliCommand;
|
||||
import org.springframework.shell.core.annotation.CliOption;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* CLI command to display rollback options.
|
||||
*/
|
||||
@Component
|
||||
public class RollbacksCommand implements CommandMarker {
|
||||
|
||||
@@ -115,7 +118,7 @@ public class RollbacksCommand implements CommandMarker {
|
||||
}
|
||||
|
||||
/**
|
||||
* An Active timeline containing only rollbacks
|
||||
* An Active timeline containing only rollbacks.
|
||||
*/
|
||||
class RollbackTimeline extends HoodieActiveTimeline {
|
||||
|
||||
|
||||
@@ -40,6 +40,9 @@ import org.springframework.shell.core.annotation.CliCommand;
|
||||
import org.springframework.shell.core.annotation.CliOption;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* CLI command to display savepoint options.
|
||||
*/
|
||||
@Component
|
||||
public class SavepointsCommand implements CommandMarker {
|
||||
|
||||
|
||||
@@ -35,12 +35,15 @@ import org.apache.log4j.Logger;
|
||||
import org.apache.spark.api.java.JavaSparkContext;
|
||||
import org.apache.spark.sql.SQLContext;
|
||||
|
||||
/**
|
||||
* This class deals with initializing spark context based on command entered to hudi-cli.
|
||||
*/
|
||||
public class SparkMain {
|
||||
|
||||
protected static final Logger LOG = Logger.getLogger(SparkMain.class);
|
||||
|
||||
/**
|
||||
* Commands
|
||||
* Commands.
|
||||
*/
|
||||
enum SparkCommand {
|
||||
ROLLBACK, DEDUPLICATE, ROLLBACK_TO_SAVEPOINT, SAVEPOINT, IMPORT, UPSERT, COMPACT_SCHEDULE, COMPACT_RUN, COMPACT_UNSCHEDULE_PLAN, COMPACT_UNSCHEDULE_FILE, COMPACT_VALIDATE, COMPACT_REPAIR
|
||||
|
||||
@@ -47,6 +47,9 @@ import org.springframework.shell.core.annotation.CliCommand;
|
||||
import org.springframework.shell.core.annotation.CliOption;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* CLI command to displays stats options.
|
||||
*/
|
||||
@Component
|
||||
public class StatsCommand implements CommandMarker {
|
||||
|
||||
|
||||
@@ -23,6 +23,9 @@ import org.springframework.shell.core.annotation.CliCommand;
|
||||
import org.springframework.shell.core.annotation.CliOption;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* CLI command to display utils.
|
||||
*/
|
||||
@Component
|
||||
public class UtilsCommand implements CommandMarker {
|
||||
|
||||
|
||||
@@ -25,6 +25,9 @@ import org.apache.hudi.common.table.HoodieTableMetaClient;
|
||||
import org.apache.hudi.common.table.HoodieTimeline;
|
||||
import org.apache.hudi.common.table.timeline.HoodieInstant;
|
||||
|
||||
/**
|
||||
* Utilities related to commit operation.
|
||||
*/
|
||||
public class CommitUtil {
|
||||
|
||||
public static long countNewRecords(HoodieTableMetaClient target, List<String> commitsToCatchup) throws IOException {
|
||||
|
||||
@@ -26,6 +26,9 @@ import java.sql.Statement;
|
||||
import org.apache.hudi.common.table.HoodieTableMetaClient;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
* Hive connection related utilities.
|
||||
*/
|
||||
public class HiveUtil {
|
||||
|
||||
private static final String driverName = "org.apache.hive.jdbc.HiveDriver";
|
||||
|
||||
@@ -24,6 +24,9 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* This class is responsible to read a Process output.
|
||||
*/
|
||||
public class InputStreamConsumer extends Thread {
|
||||
|
||||
protected static final Logger LOG = Logger.getLogger(InputStreamConsumer.class.getName());
|
||||
|
||||
@@ -29,13 +29,16 @@ import org.apache.spark.SparkConf;
|
||||
import org.apache.spark.api.java.JavaSparkContext;
|
||||
import org.apache.spark.launcher.SparkLauncher;
|
||||
|
||||
/**
|
||||
* Utility functions dealing with Spark.
|
||||
*/
|
||||
public class SparkUtil {
|
||||
|
||||
public static Logger logger = Logger.getLogger(SparkUtil.class);
|
||||
public static final String DEFUALT_SPARK_MASTER = "yarn-client";
|
||||
|
||||
/**
|
||||
* TODO: Need to fix a bunch of hardcoded stuff here eg: history server, spark distro
|
||||
* TODO: Need to fix a bunch of hardcoded stuff here eg: history server, spark distro.
|
||||
*/
|
||||
public static SparkLauncher initLauncher(String propertiesFile) throws URISyntaxException {
|
||||
String currentJar = new File(SparkUtil.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath())
|
||||
|
||||
Reference in New Issue
Block a user