1
0

[HUDI-357] Refactor hudi-cli based on new comment and code style rules (#1051)

This commit is contained in:
Gurudatt Kulkarni
2019-12-01 00:42:41 +05:30
committed by vinoth chandar
parent b65a897856
commit 75132c139f
27 changed files with 98 additions and 26 deletions

View File

@@ -25,6 +25,9 @@ import org.apache.hudi.common.table.HoodieTableMetaClient;
import org.apache.hudi.common.util.ConsistencyGuardConfig; import org.apache.hudi.common.util.ConsistencyGuardConfig;
import org.apache.hudi.common.util.FSUtils; import org.apache.hudi.common.util.FSUtils;
/**
* This class is responsible to load table metadata and hoodie related configs.
*/
public class HoodieCLI { public class HoodieCLI {
public static Configuration conf; public static Configuration conf;
@@ -35,6 +38,9 @@ public class HoodieCLI {
public static HoodieTableMetaClient tableMetadata; public static HoodieTableMetaClient tableMetadata;
public static HoodieTableMetaClient syncTableMetadata; public static HoodieTableMetaClient syncTableMetadata;
/**
* Enum for CLI state.
*/
public enum CLIState { public enum CLIState {
INIT, DATASET, SYNC INIT, DATASET, SYNC
} }

View File

@@ -23,6 +23,9 @@ import org.springframework.core.annotation.Order;
import org.springframework.shell.plugin.support.DefaultHistoryFileNameProvider; import org.springframework.shell.plugin.support.DefaultHistoryFileNameProvider;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/**
* CLI history file provider.
*/
@Component @Component
@Order(Ordered.HIGHEST_PRECEDENCE) @Order(Ordered.HIGHEST_PRECEDENCE)
public class HoodieHistoryFileNameProvider extends DefaultHistoryFileNameProvider { public class HoodieHistoryFileNameProvider extends DefaultHistoryFileNameProvider {

View File

@@ -25,12 +25,12 @@ import java.util.function.Function;
import org.apache.hudi.common.util.Option; 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 { public class HoodiePrintHelper {
/** /**
* Print header and raw rows * Print header and raw rows.
* *
* @param header Header * @param header Header
* @param rows Raw Rows * @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 rowHeader Row Header
* @param fieldNameToConverterMap Field Specific Converters * @param fieldNameToConverterMap Field Specific Converters
@@ -71,7 +71,7 @@ public class HoodiePrintHelper {
} }
/** /**
* Render rows in Table * Render rows in Table.
* *
* @param buffer Table * @param buffer Table
* @return output * @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 * @param header Table Header
* @return output * @return output
@@ -98,7 +98,7 @@ public class HoodiePrintHelper {
} }
/** /**
* Print Text table * Print Text table.
* *
* @param headers Headers * @param headers Headers
* @param data Table * @param data Table

View File

@@ -23,6 +23,9 @@ import org.springframework.core.annotation.Order;
import org.springframework.shell.plugin.support.DefaultPromptProvider; import org.springframework.shell.plugin.support.DefaultPromptProvider;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/**
* This class deals with displaying prompt on CLI based on the state.
*/
@Component @Component
@Order(Ordered.HIGHEST_PRECEDENCE) @Order(Ordered.HIGHEST_PRECEDENCE)
public class HoodiePrompt extends DefaultPromptProvider { public class HoodiePrompt extends DefaultPromptProvider {

View File

@@ -24,6 +24,9 @@ import org.springframework.shell.plugin.support.DefaultBannerProvider;
import org.springframework.shell.support.util.OsUtils; import org.springframework.shell.support.util.OsUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/**
* This class is responsible to print the splash screen at the start of the application.
*/
@Component @Component
@Order(Ordered.HIGHEST_PRECEDENCE) @Order(Ordered.HIGHEST_PRECEDENCE)
public class HoodieSplashScreen extends DefaultBannerProvider { public class HoodieSplashScreen extends DefaultBannerProvider {

View File

@@ -21,11 +21,11 @@ package org.apache.hudi.cli;
import java.io.IOException; import java.io.IOException;
import org.springframework.shell.Bootstrap; 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 { 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 { public static void main(String[] args) throws IOException {
System.out.println("Main called"); System.out.println("Main called");
new HoodieSplashScreen(); new HoodieSplashScreen();

View File

@@ -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 * @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 * @param rows Rows to be aded
* @return * @return
@@ -93,7 +93,7 @@ public class Table implements Iterable<List<String>> {
} }
/** /**
* Add all rows * Add all rows.
* *
* @param rows Rows to be added * @param rows Rows to be added
* @return * @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() { public Table flip() {
this.finishedAdding = true; 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 * @return
*/ */

View File

@@ -22,7 +22,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* Header for the table to be rendered * Header for the table to be rendered.
*/ */
public class TableHeader { public class TableHeader {
@@ -30,7 +30,7 @@ public class TableHeader {
private final List<String> fieldNames = new ArrayList<>(); private final List<String> fieldNames = new ArrayList<>();
/** /**
* Add a field (column) to table * Add a field (column) to table.
* *
* @param fieldName field Name * @param fieldName field Name
*/ */
@@ -40,14 +40,14 @@ public class TableHeader {
} }
/** /**
* Get all field names * Get all field names.
*/ */
public List<String> getFieldNames() { public List<String> getFieldNames() {
return fieldNames; return fieldNames;
} }
/** /**
* Index of the field in the table * Index of the field in the table.
* *
* @param fieldName Field Name * @param fieldName Field Name
*/ */
@@ -56,14 +56,14 @@ public class TableHeader {
} }
/** /**
* Lookup field by offset * Lookup field by offset.
*/ */
public String get(int index) { public String get(int index) {
return fieldNames.get(index); return fieldNames.get(index);
} }
/** /**
* Get number of fields in the table * Get number of fields in the table.
*/ */
public int getNumFields() { public int getNumFields() {
return fieldNames.size(); return fieldNames.size();

View File

@@ -45,6 +45,9 @@ import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption; import org.springframework.shell.core.annotation.CliOption;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/**
* CLI command to display archived commits and stats if available.
*/
@Component @Component
public class ArchivedCommitsCommand implements CommandMarker { public class ArchivedCommitsCommand implements CommandMarker {

View File

@@ -39,6 +39,9 @@ import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption; import org.springframework.shell.core.annotation.CliOption;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/**
* CLI command to show cleans options.
*/
@Component @Component
public class CleansCommand implements CommandMarker { public class CleansCommand implements CommandMarker {

View File

@@ -44,6 +44,9 @@ import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption; import org.springframework.shell.core.annotation.CliOption;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/**
* CLI command to display commits options.
*/
@Component @Component
public class CommitsCommand implements CommandMarker { public class CommitsCommand implements CommandMarker {

View File

@@ -59,6 +59,9 @@ import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption; import org.springframework.shell.core.annotation.CliOption;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/**
* CLI command to display compaction related options.
*/
@Component @Component
public class CompactionCommand implements CommandMarker { public class CompactionCommand implements CommandMarker {

View File

@@ -35,6 +35,9 @@ import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption; import org.springframework.shell.core.annotation.CliOption;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/**
* CLI command to display hudi dataset options.
*/
@Component @Component
public class DatasetsCommand implements CommandMarker { 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 path Base Path
* @param name Hoodie Table Name * @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") @CliCommand(value = "desc", help = "Describle Hoodie Table properties")
public String descTable() { public String descTable() {

View File

@@ -47,6 +47,9 @@ import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption; import org.springframework.shell.core.annotation.CliOption;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/**
* CLI command to display file system options.
*/
@Component @Component
public class FileSystemViewCommand implements CommandMarker { 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 globRegex Path Regex
* @param maxInstant Max Instants to be used for displaying file-instants * @param maxInstant Max Instants to be used for displaying file-instants

View File

@@ -33,6 +33,9 @@ import org.springframework.shell.core.annotation.CliOption;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import scala.collection.JavaConverters; import scala.collection.JavaConverters;
/**
* CLI command for importing parquet dataset to hudi dataset.
*/
@Component @Component
public class HDFSParquetImportCommand implements CommandMarker { public class HDFSParquetImportCommand implements CommandMarker {

View File

@@ -59,6 +59,9 @@ import org.springframework.stereotype.Component;
import scala.Tuple2; import scala.Tuple2;
import scala.Tuple3; import scala.Tuple3;
/**
* CLI command to display log file options.
*/
@Component @Component
public class HoodieLogFileCommand implements CommandMarker { public class HoodieLogFileCommand implements CommandMarker {

View File

@@ -32,6 +32,9 @@ import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption; import org.springframework.shell.core.annotation.CliOption;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/**
* CLI command to display sync options.
*/
@Component @Component
public class HoodieSyncCommand implements CommandMarker { public class HoodieSyncCommand implements CommandMarker {

View File

@@ -34,6 +34,9 @@ import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption; import org.springframework.shell.core.annotation.CliOption;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/**
* CLI command to display and trigger repair options.
*/
@Component @Component
public class RepairsCommand implements CommandMarker { public class RepairsCommand implements CommandMarker {

View File

@@ -42,6 +42,9 @@ import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption; import org.springframework.shell.core.annotation.CliOption;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/**
* CLI command to display rollback options.
*/
@Component @Component
public class RollbacksCommand implements CommandMarker { 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 { class RollbackTimeline extends HoodieActiveTimeline {

View File

@@ -40,6 +40,9 @@ import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption; import org.springframework.shell.core.annotation.CliOption;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/**
* CLI command to display savepoint options.
*/
@Component @Component
public class SavepointsCommand implements CommandMarker { public class SavepointsCommand implements CommandMarker {

View File

@@ -35,12 +35,15 @@ import org.apache.log4j.Logger;
import org.apache.spark.api.java.JavaSparkContext; import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.sql.SQLContext; import org.apache.spark.sql.SQLContext;
/**
* This class deals with initializing spark context based on command entered to hudi-cli.
*/
public class SparkMain { public class SparkMain {
protected static final Logger LOG = Logger.getLogger(SparkMain.class); protected static final Logger LOG = Logger.getLogger(SparkMain.class);
/** /**
* Commands * Commands.
*/ */
enum SparkCommand { enum SparkCommand {
ROLLBACK, DEDUPLICATE, ROLLBACK_TO_SAVEPOINT, SAVEPOINT, IMPORT, UPSERT, COMPACT_SCHEDULE, COMPACT_RUN, COMPACT_UNSCHEDULE_PLAN, COMPACT_UNSCHEDULE_FILE, COMPACT_VALIDATE, COMPACT_REPAIR ROLLBACK, DEDUPLICATE, ROLLBACK_TO_SAVEPOINT, SAVEPOINT, IMPORT, UPSERT, COMPACT_SCHEDULE, COMPACT_RUN, COMPACT_UNSCHEDULE_PLAN, COMPACT_UNSCHEDULE_FILE, COMPACT_VALIDATE, COMPACT_REPAIR

View File

@@ -47,6 +47,9 @@ import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption; import org.springframework.shell.core.annotation.CliOption;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/**
* CLI command to displays stats options.
*/
@Component @Component
public class StatsCommand implements CommandMarker { public class StatsCommand implements CommandMarker {

View File

@@ -23,6 +23,9 @@ import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption; import org.springframework.shell.core.annotation.CliOption;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/**
* CLI command to display utils.
*/
@Component @Component
public class UtilsCommand implements CommandMarker { public class UtilsCommand implements CommandMarker {

View File

@@ -25,6 +25,9 @@ import org.apache.hudi.common.table.HoodieTableMetaClient;
import org.apache.hudi.common.table.HoodieTimeline; import org.apache.hudi.common.table.HoodieTimeline;
import org.apache.hudi.common.table.timeline.HoodieInstant; import org.apache.hudi.common.table.timeline.HoodieInstant;
/**
* Utilities related to commit operation.
*/
public class CommitUtil { public class CommitUtil {
public static long countNewRecords(HoodieTableMetaClient target, List<String> commitsToCatchup) throws IOException { public static long countNewRecords(HoodieTableMetaClient target, List<String> commitsToCatchup) throws IOException {

View File

@@ -26,6 +26,9 @@ import java.sql.Statement;
import org.apache.hudi.common.table.HoodieTableMetaClient; import org.apache.hudi.common.table.HoodieTableMetaClient;
import org.joda.time.DateTime; import org.joda.time.DateTime;
/**
* Hive connection related utilities.
*/
public class HiveUtil { public class HiveUtil {
private static final String driverName = "org.apache.hive.jdbc.HiveDriver"; private static final String driverName = "org.apache.hive.jdbc.HiveDriver";

View File

@@ -24,6 +24,9 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.logging.Logger; import java.util.logging.Logger;
/**
* This class is responsible to read a Process output.
*/
public class InputStreamConsumer extends Thread { public class InputStreamConsumer extends Thread {
protected static final Logger LOG = Logger.getLogger(InputStreamConsumer.class.getName()); protected static final Logger LOG = Logger.getLogger(InputStreamConsumer.class.getName());

View File

@@ -29,13 +29,16 @@ import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaSparkContext; import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.launcher.SparkLauncher; import org.apache.spark.launcher.SparkLauncher;
/**
* Utility functions dealing with Spark.
*/
public class SparkUtil { public class SparkUtil {
public static Logger logger = Logger.getLogger(SparkUtil.class); public static Logger logger = Logger.getLogger(SparkUtil.class);
public static final String DEFUALT_SPARK_MASTER = "yarn-client"; 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 { public static SparkLauncher initLauncher(String propertiesFile) throws URISyntaxException {
String currentJar = new File(SparkUtil.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()) String currentJar = new File(SparkUtil.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath())