[GitHub] [hudi] zhedoubushishi commented on a change in pull request #1869: [HUDI-427] Implement CLI support for performing bootstrap

2020-08-07 Thread GitBox


zhedoubushishi commented on a change in pull request #1869:
URL: https://github.com/apache/hudi/pull/1869#discussion_r467272326



##
File path: 
hudi-common/src/main/java/org/apache/hudi/common/bootstrap/index/HFileBootstrapIndex.java
##
@@ -240,13 +240,21 @@ private HoodieBootstrapIndexInfo 
fetchBootstrapIndexInfo() throws IOException {
 @Override
 public List getIndexedPartitionPaths() {
   HFileScanner scanner = partitionIndexReader().getScanner(true, true);
-  return getAllKeys(scanner);
+  List cellKeys = getAllKeys(scanner);
+  // cellKey is in this format:
+  // part=datestr=2452537//LATEST_TIMESTAMP/Put/vlen=2405/seqid=0
+  return cellKeys.stream().map(key -> key.split("//")[0].substring(5))
+  .distinct().collect(Collectors.toList());
 }
 
 @Override
 public List getIndexedFileIds() {
   HFileScanner scanner = fileIdIndexReader().getScanner(true, true);
-  return getAllKeys(scanner);
+  List cellKeys = getAllKeys(scanner);
+  // cellKey is in this format:
+  // 
part=datestr=2452537;fileid=baab9c50-c35e-49d1-b928-695aa7e37833//LATEST_TIMESTAMP/Put/vlen=2312/seqid=0
+  return cellKeys.stream().map(key -> 
key.split("//")[0].split(";")[1].split("=")[1])

Review comment:
   @bvaradar thanks! PR #1933 looks good to me. Migrated it into current PR.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [hudi] zhedoubushishi commented on a change in pull request #1869: [HUDI-427] Implement CLI support for performing bootstrap

2020-08-06 Thread GitBox


zhedoubushishi commented on a change in pull request #1869:
URL: https://github.com/apache/hudi/pull/1869#discussion_r466696366



##
File path: 
hudi-common/src/main/java/org/apache/hudi/common/bootstrap/index/HFileBootstrapIndex.java
##
@@ -240,13 +240,21 @@ private HoodieBootstrapIndexInfo 
fetchBootstrapIndexInfo() throws IOException {
 @Override
 public List getIndexedPartitionPaths() {
   HFileScanner scanner = partitionIndexReader().getScanner(true, true);
-  return getAllKeys(scanner);
+  List cellKeys = getAllKeys(scanner);
+  // cellKey is in this format:
+  // part=datestr=2452537//LATEST_TIMESTAMP/Put/vlen=2405/seqid=0
+  return cellKeys.stream().map(key -> key.split("//")[0].substring(5))
+  .distinct().collect(Collectors.toList());
 }
 
 @Override
 public List getIndexedFileIds() {
   HFileScanner scanner = fileIdIndexReader().getScanner(true, true);
-  return getAllKeys(scanner);
+  List cellKeys = getAllKeys(scanner);
+  // cellKey is in this format:
+  // 
part=datestr=2452537;fileid=baab9c50-c35e-49d1-b928-695aa7e37833//LATEST_TIMESTAMP/Put/vlen=2312/seqid=0
+  return cellKeys.stream().map(key -> 
key.split("//")[0].split(";")[1].split("=")[1])

Review comment:
   This is a known issue: https://issues.apache.org/jira/browse/HUDI-971





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [hudi] zhedoubushishi commented on a change in pull request #1869: [HUDI-427] Implement CLI support for performing bootstrap

2020-08-06 Thread GitBox


zhedoubushishi commented on a change in pull request #1869:
URL: https://github.com/apache/hudi/pull/1869#discussion_r466589747



##
File path: 
hudi-cli/src/main/java/org/apache/hudi/cli/commands/BootstrapCommand.java
##
@@ -0,0 +1,184 @@
+/*
+ * 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.cli.commands;
+
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.cli.HoodiePrintHelper;
+import org.apache.hudi.cli.TableHeader;
+import org.apache.hudi.cli.commands.SparkMain.SparkCommand;
+import org.apache.hudi.cli.utils.InputStreamConsumer;
+import org.apache.hudi.cli.utils.SparkUtil;
+import org.apache.hudi.common.bootstrap.index.BootstrapIndex;
+import org.apache.hudi.common.model.BootstrapFileMapping;
+import org.apache.hudi.common.model.HoodieFileGroupId;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.utilities.UtilHelpers;
+
+import org.apache.spark.launcher.SparkLauncher;
+import org.apache.spark.util.Utils;
+import org.springframework.shell.core.CommandMarker;
+import org.springframework.shell.core.annotation.CliCommand;
+import org.springframework.shell.core.annotation.CliOption;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import scala.collection.JavaConverters;
+
+/**
+ * CLI command to perform bootstrap action & display bootstrap index.
+ */
+@Component
+public class BootstrapCommand implements CommandMarker {
+
+  @CliCommand(value = "bootstrap run", help = "Run a bootstrap action for 
current Hudi table")
+  public String bootstrap(
+  @CliOption(key = {"srcPath"}, mandatory = true, help = "Bootstrap source 
data path of the table") final String srcPath,
+  @CliOption(key = {"targetPath"}, mandatory = true,
+  help = "Base path for the target hoodie table") final String 
targetPath,
+  @CliOption(key = {"tableName"}, mandatory = true, help = "Hoodie table 
name") final String tableName,
+  @CliOption(key = {"tableType"}, mandatory = true, help = "Hoodie table 
type") final String tableType,
+  @CliOption(key = {"rowKeyField"}, mandatory = true, help = "Record key 
columns for bootstrap data") final String rowKeyField,
+  @CliOption(key = {"partitionPathField"}, unspecifiedDefaultValue = "",
+  help = "Partition fields for bootstrap source data") final String 
partitionPathField,
+  @CliOption(key = {"bootstrapIndexClass"}, unspecifiedDefaultValue = 
"org.apache.hudi.common.bootstrap.index.HFileBootstrapIndex",
+  help = "Bootstrap Index Class") final String bootstrapIndexClass,
+  @CliOption(key = {"selectorClass"}, unspecifiedDefaultValue = 
"org.apache.hudi.client.bootstrap.selector.MetadataOnlyBootstrapModeSelector",
+  help = "Selector class for bootstrap") final String selectorClass,
+  @CliOption(key = {"keyGeneratorClass"}, unspecifiedDefaultValue = 
"org.apache.hudi.keygen.SimpleKeyGenerator",
+  help = "Key generator class for bootstrap") final String 
keyGeneratorClass,
+  @CliOption(key = {"fullBootstrapInputProvider"}, unspecifiedDefaultValue 
= "org.apache.hudi.bootstrap.SparkParquetBootstrapDataProvider",
+  help = "Class for Full bootstrap input provider") final String 
fullBootstrapInputProvider,
+  @CliOption(key = {"schemaProviderClass"}, unspecifiedDefaultValue = "",
+  help = "SchemaProvider to attach schemas to bootstrap source data") 
final String schemaProviderClass,
+  @CliOption(key = {"payloadClass"}, unspecifiedDefaultValue = 
"org.apache.hudi.common.model.HoodieAvroPayload",
+  help = "Payload Class") final String payloadClass,
+  @CliOption(key = {"parallelism"}, unspecifiedDefaultValue = "1500", help 
= "Bootstrap writer parallelism") final int parallelism,
+  @CliOption(key = {"sparkMaster"}, unspecifiedDefaultValue = "", help = 
"Spark Master") String master,
+  @CliOption(key = {"sparkMemory"}, unspecifiedDefaultValue = "4G", help = 
"Spark executor memory") final String 

[GitHub] [hudi] zhedoubushishi commented on a change in pull request #1869: [HUDI-427] Implement CLI support for performing bootstrap

2020-08-06 Thread GitBox


zhedoubushishi commented on a change in pull request #1869:
URL: https://github.com/apache/hudi/pull/1869#discussion_r466589474



##
File path: 
hudi-common/src/main/java/org/apache/hudi/common/bootstrap/index/HFileBootstrapIndex.java
##
@@ -240,13 +240,21 @@ private HoodieBootstrapIndexInfo 
fetchBootstrapIndexInfo() throws IOException {
 @Override
 public List getIndexedPartitionPaths() {
   HFileScanner scanner = partitionIndexReader().getScanner(true, true);
-  return getAllKeys(scanner);
+  List cellKeys = getAllKeys(scanner);
+  // cellKey is in this format:
+  // part=datestr=2452537//LATEST_TIMESTAMP/Put/vlen=2405/seqid=0
+  return cellKeys.stream().map(key -> key.split("//")[0].substring(5))
+  .distinct().collect(Collectors.toList());
 }
 
 @Override
 public List getIndexedFileIds() {
   HFileScanner scanner = fileIdIndexReader().getScanner(true, true);
-  return getAllKeys(scanner);
+  List cellKeys = getAllKeys(scanner);
+  // cellKey is in this format:
+  // 
part=datestr=2452537;fileid=baab9c50-c35e-49d1-b928-695aa7e37833//LATEST_TIMESTAMP/Put/vlen=2312/seqid=0
+  return cellKeys.stream().map(key -> 
key.split("//")[0].split(";")[1].split("=")[1])

Review comment:
   These two methods are only called in ```TestBootstrapIndex```. And what 
it does in the test code is to check the size of the result, so that's why we 
fail to catch this error before. Let me create a separate commit/pr to include 
this fix and also add some test cases to cover these two methods.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [hudi] zhedoubushishi commented on a change in pull request #1869: [HUDI-427] Implement CLI support for performing bootstrap

2020-08-06 Thread GitBox


zhedoubushishi commented on a change in pull request #1869:
URL: https://github.com/apache/hudi/pull/1869#discussion_r466572098



##
File path: 
hudi-cli/src/main/java/org/apache/hudi/cli/commands/BootstrapCommand.java
##
@@ -0,0 +1,184 @@
+/*
+ * 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.cli.commands;
+
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.cli.HoodiePrintHelper;
+import org.apache.hudi.cli.TableHeader;
+import org.apache.hudi.cli.commands.SparkMain.SparkCommand;
+import org.apache.hudi.cli.utils.InputStreamConsumer;
+import org.apache.hudi.cli.utils.SparkUtil;
+import org.apache.hudi.common.bootstrap.index.BootstrapIndex;
+import org.apache.hudi.common.model.BootstrapFileMapping;
+import org.apache.hudi.common.model.HoodieFileGroupId;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.utilities.UtilHelpers;
+
+import org.apache.spark.launcher.SparkLauncher;
+import org.apache.spark.util.Utils;
+import org.springframework.shell.core.CommandMarker;
+import org.springframework.shell.core.annotation.CliCommand;
+import org.springframework.shell.core.annotation.CliOption;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import scala.collection.JavaConverters;
+
+/**
+ * CLI command to perform bootstrap action & display bootstrap index.
+ */
+@Component
+public class BootstrapCommand implements CommandMarker {
+
+  @CliCommand(value = "bootstrap run", help = "Run a bootstrap action for 
current Hudi table")
+  public String bootstrap(
+  @CliOption(key = {"srcPath"}, mandatory = true, help = "Bootstrap source 
data path of the table") final String srcPath,
+  @CliOption(key = {"targetPath"}, mandatory = true,
+  help = "Base path for the target hoodie table") final String 
targetPath,
+  @CliOption(key = {"tableName"}, mandatory = true, help = "Hoodie table 
name") final String tableName,
+  @CliOption(key = {"tableType"}, mandatory = true, help = "Hoodie table 
type") final String tableType,
+  @CliOption(key = {"rowKeyField"}, mandatory = true, help = "Record key 
columns for bootstrap data") final String rowKeyField,
+  @CliOption(key = {"partitionPathField"}, unspecifiedDefaultValue = "",
+  help = "Partition fields for bootstrap source data") final String 
partitionPathField,
+  @CliOption(key = {"bootstrapIndexClass"}, unspecifiedDefaultValue = 
"org.apache.hudi.common.bootstrap.index.HFileBootstrapIndex",
+  help = "Bootstrap Index Class") final String bootstrapIndexClass,
+  @CliOption(key = {"selectorClass"}, unspecifiedDefaultValue = 
"org.apache.hudi.client.bootstrap.selector.MetadataOnlyBootstrapModeSelector",
+  help = "Selector class for bootstrap") final String selectorClass,
+  @CliOption(key = {"keyGeneratorClass"}, unspecifiedDefaultValue = 
"org.apache.hudi.keygen.SimpleKeyGenerator",
+  help = "Key generator class for bootstrap") final String 
keyGeneratorClass,
+  @CliOption(key = {"fullBootstrapInputProvider"}, unspecifiedDefaultValue 
= "org.apache.hudi.bootstrap.SparkParquetBootstrapDataProvider",
+  help = "Class for Full bootstrap input provider") final String 
fullBootstrapInputProvider,
+  @CliOption(key = {"schemaProviderClass"}, unspecifiedDefaultValue = "",
+  help = "SchemaProvider to attach schemas to bootstrap source data") 
final String schemaProviderClass,
+  @CliOption(key = {"payloadClass"}, unspecifiedDefaultValue = 
"org.apache.hudi.common.model.HoodieAvroPayload",

Review comment:
   I see. I saw create table command uses ```HoodieAvroPayload```: 
https://github.com/apache/hudi/blob/master/hudi-cli/src/main/java/org/apache/hudi/cli/commands/TableCommand.java#L90.
   
   But since deltastreamer and spark datasource both use 
```OverwriteWithLatestAvroPayload```, I think we should also change the default 
value of create table command to make it consistent.





[GitHub] [hudi] zhedoubushishi commented on a change in pull request #1869: [HUDI-427] Implement CLI support for performing bootstrap

2020-08-06 Thread GitBox


zhedoubushishi commented on a change in pull request #1869:
URL: https://github.com/apache/hudi/pull/1869#discussion_r466562083



##
File path: 
hudi-cli/src/main/java/org/apache/hudi/cli/commands/BootstrapCommand.java
##
@@ -0,0 +1,184 @@
+/*
+ * 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.cli.commands;
+
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.cli.HoodiePrintHelper;
+import org.apache.hudi.cli.TableHeader;
+import org.apache.hudi.cli.commands.SparkMain.SparkCommand;
+import org.apache.hudi.cli.utils.InputStreamConsumer;
+import org.apache.hudi.cli.utils.SparkUtil;
+import org.apache.hudi.common.bootstrap.index.BootstrapIndex;
+import org.apache.hudi.common.model.BootstrapFileMapping;
+import org.apache.hudi.common.model.HoodieFileGroupId;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.utilities.UtilHelpers;
+
+import org.apache.spark.launcher.SparkLauncher;
+import org.apache.spark.util.Utils;
+import org.springframework.shell.core.CommandMarker;
+import org.springframework.shell.core.annotation.CliCommand;
+import org.springframework.shell.core.annotation.CliOption;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import scala.collection.JavaConverters;
+
+/**
+ * CLI command to perform bootstrap action & display bootstrap index.
+ */
+@Component
+public class BootstrapCommand implements CommandMarker {
+
+  @CliCommand(value = "bootstrap run", help = "Run a bootstrap action for 
current Hudi table")
+  public String bootstrap(
+  @CliOption(key = {"srcPath"}, mandatory = true, help = "Bootstrap source 
data path of the table") final String srcPath,
+  @CliOption(key = {"targetPath"}, mandatory = true,
+  help = "Base path for the target hoodie table") final String 
targetPath,
+  @CliOption(key = {"tableName"}, mandatory = true, help = "Hoodie table 
name") final String tableName,
+  @CliOption(key = {"tableType"}, mandatory = true, help = "Hoodie table 
type") final String tableType,
+  @CliOption(key = {"rowKeyField"}, mandatory = true, help = "Record key 
columns for bootstrap data") final String rowKeyField,
+  @CliOption(key = {"partitionPathField"}, unspecifiedDefaultValue = "",
+  help = "Partition fields for bootstrap source data") final String 
partitionPathField,
+  @CliOption(key = {"bootstrapIndexClass"}, unspecifiedDefaultValue = 
"org.apache.hudi.common.bootstrap.index.HFileBootstrapIndex",
+  help = "Bootstrap Index Class") final String bootstrapIndexClass,
+  @CliOption(key = {"selectorClass"}, unspecifiedDefaultValue = 
"org.apache.hudi.client.bootstrap.selector.MetadataOnlyBootstrapModeSelector",
+  help = "Selector class for bootstrap") final String selectorClass,
+  @CliOption(key = {"keyGeneratorClass"}, unspecifiedDefaultValue = 
"org.apache.hudi.keygen.SimpleKeyGenerator",
+  help = "Key generator class for bootstrap") final String 
keyGeneratorClass,
+  @CliOption(key = {"fullBootstrapInputProvider"}, unspecifiedDefaultValue 
= "org.apache.hudi.bootstrap.SparkParquetBootstrapDataProvider",
+  help = "Class for Full bootstrap input provider") final String 
fullBootstrapInputProvider,
+  @CliOption(key = {"schemaProviderClass"}, unspecifiedDefaultValue = "",
+  help = "SchemaProvider to attach schemas to bootstrap source data") 
final String schemaProviderClass,
+  @CliOption(key = {"payloadClass"}, unspecifiedDefaultValue = 
"org.apache.hudi.common.model.HoodieAvroPayload",
+  help = "Payload Class") final String payloadClass,
+  @CliOption(key = {"parallelism"}, unspecifiedDefaultValue = "1500", help 
= "Bootstrap writer parallelism") final int parallelism,
+  @CliOption(key = {"sparkMaster"}, unspecifiedDefaultValue = "", help = 
"Spark Master") String master,
+  @CliOption(key = {"sparkMemory"}, unspecifiedDefaultValue = "4G", help = 
"Spark executor memory") final String 

[GitHub] [hudi] zhedoubushishi commented on a change in pull request #1869: [HUDI-427] Implement CLI support for performing bootstrap

2020-08-05 Thread GitBox


zhedoubushishi commented on a change in pull request #1869:
URL: https://github.com/apache/hudi/pull/1869#discussion_r465872403



##
File path: 
hudi-cli/src/main/java/org/apache/hudi/cli/commands/BootstrapCommand.java
##
@@ -0,0 +1,189 @@
+/*
+ * 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.cli.commands;
+
+import org.apache.hudi.avro.model.BootstrapIndexInfo;
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.cli.HoodiePrintHelper;
+import org.apache.hudi.cli.TableHeader;
+import org.apache.hudi.cli.commands.SparkMain.SparkCommand;
+import org.apache.hudi.cli.utils.InputStreamConsumer;
+import org.apache.hudi.cli.utils.SparkUtil;
+import org.apache.hudi.common.model.BootstrapSourceFileMapping;
+import org.apache.hudi.common.model.HoodieFileGroupId;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.utilities.UtilHelpers;
+
+import org.apache.spark.launcher.SparkLauncher;
+import org.apache.spark.util.Utils;
+import org.springframework.shell.core.CommandMarker;
+import org.springframework.shell.core.annotation.CliCommand;
+import org.springframework.shell.core.annotation.CliOption;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import scala.collection.JavaConverters;
+
+/**
+ * CLI command to perform bootstrap action & display bootstrap index.
+ */
+@Component
+public class BootstrapCommand implements CommandMarker {
+
+  @CliCommand(value = "bootstrap run", help = "Run a bootstrap action for 
current Hudi table")
+  public String bootstrap(
+  @CliOption(key = {"sourcePath"}, mandatory = true, help = "Source data 
path of the table") final String sourcePath,
+  @CliOption(key = {"recordKeyColumns"}, mandatory = true, help = "Record 
key columns for bootstrap data") final String recordKeyCols,
+  @CliOption(key = {"partitionFields"}, unspecifiedDefaultValue = "", help 
= "Partition fields for bootstrap data") final String partitionsFields,
+  @CliOption(key = {"parallelism"}, unspecifiedDefaultValue = "1500", help 
= "Bootstrap writer parallelism") final int parallelism,
+  @CliOption(key = {"schema"}, unspecifiedDefaultValue = "", help = 
"Schema of the source data file") final String schema,
+  @CliOption(key = {"selectorClass"}, unspecifiedDefaultValue = 
"org.apache.hudi.client.bootstrap.selector.MetadataOnlyBootstrapModeSelector",
+  help = "Selector class for bootstrap") final String selectorClass,
+  @CliOption(key = {"keyGeneratorClass"}, unspecifiedDefaultValue = 
"org.apache.hudi.keygen.SimpleKeyGenerator",
+  help = "Key generator class for bootstrap") final String 
keyGeneratorClass,
+  @CliOption(key = {"fullBootstrapInputProvider"}, unspecifiedDefaultValue 
= "org.apache.hudi.bootstrap.SparkDataSourceBasedFullBootstrapInputProvider",
+  help = "Class for Full bootstrap input provider") final String 
fullBootstrapInputProvider,
+  @CliOption(key = "sparkMaster", unspecifiedDefaultValue = "", help = 
"Spark Master") String master,
+  @CliOption(key = "sparkMemory", unspecifiedDefaultValue = "4G", help = 
"Spark executor memory") final String sparkMemory)
+  throws IOException, InterruptedException, URISyntaxException {
+
+boolean initialized = HoodieCLI.initConf();
+HoodieCLI.initFS(initialized);
+HoodieTableMetaClient metaClient = HoodieCLI.getTableMetaClient();
+
+String sparkPropertiesPath =
+
Utils.getDefaultPropertiesFile(JavaConverters.mapAsScalaMapConverter(System.getenv()).asScala());
+
+SparkLauncher sparkLauncher = SparkUtil.initLauncher(sparkPropertiesPath);
+
+String cmd = SparkCommand.BOOTSTRAP.toString();
+
+sparkLauncher.addAppArgs(cmd, master, sparkMemory, 
metaClient.getTableConfig().getTableName(), metaClient.getBasePath(), 
sourcePath, schema, recordKeyCols,
+partitionsFields, String.valueOf(parallelism), selectorClass, 
keyGeneratorClass, fullBootstrapInputProvider);
+

[GitHub] [hudi] zhedoubushishi commented on a change in pull request #1869: [HUDI-427] Implement CLI support for performing bootstrap

2020-08-04 Thread GitBox


zhedoubushishi commented on a change in pull request #1869:
URL: https://github.com/apache/hudi/pull/1869#discussion_r465457779



##
File path: 
hudi-cli/src/main/java/org/apache/hudi/cli/commands/BootstrapCommand.java
##
@@ -0,0 +1,189 @@
+/*
+ * 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.cli.commands;
+
+import org.apache.hudi.avro.model.BootstrapIndexInfo;
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.cli.HoodiePrintHelper;
+import org.apache.hudi.cli.TableHeader;
+import org.apache.hudi.cli.commands.SparkMain.SparkCommand;
+import org.apache.hudi.cli.utils.InputStreamConsumer;
+import org.apache.hudi.cli.utils.SparkUtil;
+import org.apache.hudi.common.model.BootstrapSourceFileMapping;
+import org.apache.hudi.common.model.HoodieFileGroupId;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.utilities.UtilHelpers;
+
+import org.apache.spark.launcher.SparkLauncher;
+import org.apache.spark.util.Utils;
+import org.springframework.shell.core.CommandMarker;
+import org.springframework.shell.core.annotation.CliCommand;
+import org.springframework.shell.core.annotation.CliOption;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import scala.collection.JavaConverters;
+
+/**
+ * CLI command to perform bootstrap action & display bootstrap index.
+ */
+@Component
+public class BootstrapCommand implements CommandMarker {
+
+  @CliCommand(value = "bootstrap run", help = "Run a bootstrap action for 
current Hudi table")
+  public String bootstrap(

Review comment:
   I reconsidered about this issue. I agreed that we can run 
```bootstrap``` as what ```HDFSParquetImportCommand``` does. So we only need to 
connect to the table when we want to get index info.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [hudi] zhedoubushishi commented on a change in pull request #1869: [HUDI-427] Implement CLI support for performing bootstrap

2020-08-04 Thread GitBox


zhedoubushishi commented on a change in pull request #1869:
URL: https://github.com/apache/hudi/pull/1869#discussion_r465457434



##
File path: 
hudi-cli/src/test/java/org/apache/hudi/cli/integ/ITTestBootstrapCommand.java
##
@@ -0,0 +1,108 @@
+/*
+ * 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.cli.integ;
+
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.cli.HoodiePrintHelper;
+import org.apache.hudi.cli.commands.TableCommand;
+import org.apache.hudi.cli.testutils.AbstractShellIntegrationTest;
+import org.apache.hudi.common.model.HoodieTableType;
+import org.apache.hudi.common.table.timeline.versioning.TimelineLayoutVersion;
+import org.apache.hudi.testutils.HoodieTestDataGenerator;
+
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.SaveMode;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.shell.core.CommandResult;
+
+import java.io.File;
+import java.io.IOException;
+import java.time.Instant;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Test class of {@link org.apache.hudi.cli.commands.BootstrapCommand}.
+ */
+public class ITTestBootstrapCommand extends AbstractShellIntegrationTest {
+
+  private static final int TOTAL_RECORDS = 100;
+  private static final String PARTITION_FIELD = "datestr";
+  private static final String RECORD_KEY_FIELD = "_row_key";
+
+  private String sourcePath;
+  private String tablePath;
+  private List partitions;
+
+  @BeforeEach
+  public void init() throws IOException {
+String srcName = "source";
+String tableName = "test-table";
+sourcePath = basePath + File.separator + srcName;
+tablePath = basePath + File.separator + tableName;
+
+partitions = Arrays.asList("2018", "2019", "2020");
+double timestamp = new Double(Instant.now().toEpochMilli()).longValue();
+Dataset df = 
HoodieTestDataGenerator.generateTestRawTripDataset(timestamp,
+TOTAL_RECORDS, partitions, jsc, sqlContext);
+
df.write().partitionBy("datestr").format("parquet").mode(SaveMode.Overwrite).save(sourcePath);
+
+// Create table and connect
+new TableCommand().createTable(
+tablePath, tableName, HoodieTableType.COPY_ON_WRITE.name(),
+"", TimelineLayoutVersion.VERSION_1, 
"org.apache.hudi.common.model.HoodieAvroPayload",
+"org.apache.hudi.common.bootstrap.index.HFileBasedBootstrapIndex");
+  }
+
+  /**
+   * Test case for command 'bootstrap'.
+   */
+  @Test
+  public void testBootstrapRunCommand() throws IOException {
+// test bootstrap run command
+String cmdStr = String.format("bootstrap run --sourcePath %s 
--recordKeyColumns %s --partitionFields %s --sparkMaster %s",
+sourcePath, RECORD_KEY_FIELD, PARTITION_FIELD, "local");
+CommandResult cr = getShell().executeCommand(cmdStr);
+assertTrue(cr.isSuccess());
+
+// Check hudi table exist
+new TableCommand().connect(tablePath, TimelineLayoutVersion.VERSION_1, 
false, 2000, 30, 7);
+metaClient = HoodieCLI.getTableMetaClient();
+assertEquals(1, 
metaClient.getActiveTimeline().getCommitsTimeline().countInstants(), "Should 
have 1 commit.");
+
+// test bootstrap show indexed partitions

Review comment:
   Added another two test cases for ```bootstrap index showMapping```.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [hudi] zhedoubushishi commented on a change in pull request #1869: [HUDI-427] Implement CLI support for performing bootstrap

2020-08-03 Thread GitBox


zhedoubushishi commented on a change in pull request #1869:
URL: https://github.com/apache/hudi/pull/1869#discussion_r464605104



##
File path: 
hudi-cli/src/main/java/org/apache/hudi/cli/commands/BootstrapCommand.java
##
@@ -0,0 +1,189 @@
+/*
+ * 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.cli.commands;
+
+import org.apache.hudi.avro.model.BootstrapIndexInfo;
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.cli.HoodiePrintHelper;
+import org.apache.hudi.cli.TableHeader;
+import org.apache.hudi.cli.commands.SparkMain.SparkCommand;
+import org.apache.hudi.cli.utils.InputStreamConsumer;
+import org.apache.hudi.cli.utils.SparkUtil;
+import org.apache.hudi.common.model.BootstrapSourceFileMapping;
+import org.apache.hudi.common.model.HoodieFileGroupId;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.utilities.UtilHelpers;
+
+import org.apache.spark.launcher.SparkLauncher;
+import org.apache.spark.util.Utils;
+import org.springframework.shell.core.CommandMarker;
+import org.springframework.shell.core.annotation.CliCommand;
+import org.springframework.shell.core.annotation.CliOption;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import scala.collection.JavaConverters;
+
+/**
+ * CLI command to perform bootstrap action & display bootstrap index.
+ */
+@Component
+public class BootstrapCommand implements CommandMarker {
+
+  @CliCommand(value = "bootstrap run", help = "Run a bootstrap action for 
current Hudi table")
+  public String bootstrap(
+  @CliOption(key = {"sourcePath"}, mandatory = true, help = "Source data 
path of the table") final String sourcePath,
+  @CliOption(key = {"recordKeyColumns"}, mandatory = true, help = "Record 
key columns for bootstrap data") final String recordKeyCols,
+  @CliOption(key = {"partitionFields"}, unspecifiedDefaultValue = "", help 
= "Partition fields for bootstrap data") final String partitionsFields,
+  @CliOption(key = {"parallelism"}, unspecifiedDefaultValue = "1500", help 
= "Bootstrap writer parallelism") final int parallelism,
+  @CliOption(key = {"schema"}, unspecifiedDefaultValue = "", help = 
"Schema of the source data file") final String schema,
+  @CliOption(key = {"selectorClass"}, unspecifiedDefaultValue = 
"org.apache.hudi.client.bootstrap.selector.MetadataOnlyBootstrapModeSelector",
+  help = "Selector class for bootstrap") final String selectorClass,
+  @CliOption(key = {"keyGeneratorClass"}, unspecifiedDefaultValue = 
"org.apache.hudi.keygen.SimpleKeyGenerator",
+  help = "Key generator class for bootstrap") final String 
keyGeneratorClass,
+  @CliOption(key = {"fullBootstrapInputProvider"}, unspecifiedDefaultValue 
= "org.apache.hudi.bootstrap.SparkDataSourceBasedFullBootstrapInputProvider",
+  help = "Class for Full bootstrap input provider") final String 
fullBootstrapInputProvider,
+  @CliOption(key = "sparkMaster", unspecifiedDefaultValue = "", help = 
"Spark Master") String master,
+  @CliOption(key = "sparkMemory", unspecifiedDefaultValue = "4G", help = 
"Spark executor memory") final String sparkMemory)
+  throws IOException, InterruptedException, URISyntaxException {
+
+boolean initialized = HoodieCLI.initConf();
+HoodieCLI.initFS(initialized);
+HoodieTableMetaClient metaClient = HoodieCLI.getTableMetaClient();
+
+String sparkPropertiesPath =
+
Utils.getDefaultPropertiesFile(JavaConverters.mapAsScalaMapConverter(System.getenv()).asScala());
+
+SparkLauncher sparkLauncher = SparkUtil.initLauncher(sparkPropertiesPath);
+
+String cmd = SparkCommand.BOOTSTRAP.toString();
+
+sparkLauncher.addAppArgs(cmd, master, sparkMemory, 
metaClient.getTableConfig().getTableName(), metaClient.getBasePath(), 
sourcePath, schema, recordKeyCols,
+partitionsFields, String.valueOf(parallelism), selectorClass, 
keyGeneratorClass, fullBootstrapInputProvider);
+

[GitHub] [hudi] zhedoubushishi commented on a change in pull request #1869: [HUDI-427] Implement CLI support for performing bootstrap

2020-08-03 Thread GitBox


zhedoubushishi commented on a change in pull request #1869:
URL: https://github.com/apache/hudi/pull/1869#discussion_r464604511



##
File path: 
hudi-cli/src/main/java/org/apache/hudi/cli/commands/BootstrapCommand.java
##
@@ -0,0 +1,189 @@
+/*
+ * 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.cli.commands;
+
+import org.apache.hudi.avro.model.BootstrapIndexInfo;
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.cli.HoodiePrintHelper;
+import org.apache.hudi.cli.TableHeader;
+import org.apache.hudi.cli.commands.SparkMain.SparkCommand;
+import org.apache.hudi.cli.utils.InputStreamConsumer;
+import org.apache.hudi.cli.utils.SparkUtil;
+import org.apache.hudi.common.model.BootstrapSourceFileMapping;
+import org.apache.hudi.common.model.HoodieFileGroupId;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.utilities.UtilHelpers;
+
+import org.apache.spark.launcher.SparkLauncher;
+import org.apache.spark.util.Utils;
+import org.springframework.shell.core.CommandMarker;
+import org.springframework.shell.core.annotation.CliCommand;
+import org.springframework.shell.core.annotation.CliOption;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import scala.collection.JavaConverters;
+
+/**
+ * CLI command to perform bootstrap action & display bootstrap index.
+ */
+@Component
+public class BootstrapCommand implements CommandMarker {
+
+  @CliCommand(value = "bootstrap run", help = "Run a bootstrap action for 
current Hudi table")
+  public String bootstrap(
+  @CliOption(key = {"sourcePath"}, mandatory = true, help = "Source data 
path of the table") final String sourcePath,
+  @CliOption(key = {"recordKeyColumns"}, mandatory = true, help = "Record 
key columns for bootstrap data") final String recordKeyCols,
+  @CliOption(key = {"partitionFields"}, unspecifiedDefaultValue = "", help 
= "Partition fields for bootstrap data") final String partitionsFields,

Review comment:
   Done.

##
File path: 
hudi-cli/src/main/java/org/apache/hudi/cli/commands/BootstrapCommand.java
##
@@ -0,0 +1,189 @@
+/*
+ * 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.cli.commands;
+
+import org.apache.hudi.avro.model.BootstrapIndexInfo;
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.cli.HoodiePrintHelper;
+import org.apache.hudi.cli.TableHeader;
+import org.apache.hudi.cli.commands.SparkMain.SparkCommand;
+import org.apache.hudi.cli.utils.InputStreamConsumer;
+import org.apache.hudi.cli.utils.SparkUtil;
+import org.apache.hudi.common.model.BootstrapSourceFileMapping;
+import org.apache.hudi.common.model.HoodieFileGroupId;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.utilities.UtilHelpers;
+
+import org.apache.spark.launcher.SparkLauncher;
+import org.apache.spark.util.Utils;
+import org.springframework.shell.core.CommandMarker;
+import org.springframework.shell.core.annotation.CliCommand;
+import org.springframework.shell.core.annotation.CliOption;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.ArrayList;