Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docker/demo/sparksql-batch2.commands
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ spark.sql("select `_hoodie_commit_time`, symbol, ts, volume, open, close from s
spark.sql("select symbol, max(ts) from stock_ticks_mor_rt group by symbol HAVING symbol = 'GOOG'").show(100, false)
spark.sql("select `_hoodie_commit_time`, symbol, ts, volume, open, close from stock_ticks_mor_rt where symbol = 'GOOG'").show(100, false)

// Copy COW as parquet dataset for bootstrap
val df = spark.sql("select _hoodie_record_key, volume, ts, symbol, year, month, high, low key, date, close, open, day, dt from stock_ticks_cow")
df.withColumnRenamed("_hoodie_record_key", "_row_key").write.parquet("/user/hive/warehouse/stock_ticks_cow_parquet")

System.exit(0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.bootstrap;

import org.apache.hudi.client.utils.ClientUtils;
import org.apache.hudi.config.HoodieWriteConfig;

import org.apache.avro.generic.GenericRecord;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class BootstrapKeyGenerator implements Serializable {

private final HoodieWriteConfig writeConfig;
private final List<String> keyColumns;
private final List<String> topLevelKeyColumns;

public BootstrapKeyGenerator(HoodieWriteConfig writeConfig) {
this.writeConfig = writeConfig;
this.keyColumns = Arrays.asList(writeConfig.getBootstrapRecordKeyColumns().split(","));
// For nested columns, pick top level column name
this.topLevelKeyColumns = keyColumns.stream().map(k -> {
int idx = k.indexOf('.');
return idx > 0 ? k.substring(0, idx) : k;
}).collect(Collectors.toList());
}

/**
* Returns record key from generic record. The generic record
*/
public String getRecordKey(GenericRecord record) {
return keyColumns.stream().map(key -> ClientUtils.getNestedFieldValAsString(record, key))
.collect(Collectors.joining("_"));
}

public List<String> getKeyColumns() {
return keyColumns;
}

public List<String> getTopLevelKeyColumns() {
return topLevelKeyColumns;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.bootstrap;

import org.apache.hudi.common.util.collection.Pair;
import org.apache.hudi.config.HoodieWriteConfig;
import org.apache.hudi.config.HoodieWriteConfig.BootstrapMode;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

public abstract class BootstrapPartitionSelector implements Serializable {

protected final HoodieWriteConfig writeConfig;

public BootstrapPartitionSelector(HoodieWriteConfig writeConfig) {
this.writeConfig = writeConfig;
}

/**
* Classify partitions for the purpose of bootstrapping.
* @param partitions List of partitions with files present in each partitions
* @return a partitions grouped by bootstrap mode
*/
public abstract Map<BootstrapMode, List<Pair<String, List<String>>>> select(
List<Pair<String, List<String>>> partitions);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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.bootstrap;

import org.apache.hudi.WriteStatus;
import org.apache.hudi.common.model.HoodieWriteStat;
import org.apache.hudi.common.util.collection.Pair;

import java.io.Serializable;

/**
* WriteStatus for Bootstrap.
*/
public class BootstrapWriteStatus extends WriteStatus {

public static final class BootstrapSourceInfo implements Serializable {
private final String bootstrapBasePath;
private final String bootstrapPartitionPath;
private final String fileName;

public BootstrapSourceInfo(String bootstrapBasePath, String bootstrapPartitionPath, String fileName) {
this.bootstrapBasePath = bootstrapBasePath;
this.bootstrapPartitionPath = bootstrapPartitionPath;
this.fileName = fileName;
}

public String getBootstrapBasePath() {
return bootstrapBasePath;
}

public String getBootstrapPartitionPath() {
return bootstrapPartitionPath;
}

public String getFileName() {
return fileName;
}
}

private BootstrapSourceInfo bootstrapSourceInfo;

public BootstrapWriteStatus(Boolean trackSuccessRecords, Double failureFraction) {
super(trackSuccessRecords, failureFraction);
}

public BootstrapSourceInfo getBootstrapSourceInfo() {
return bootstrapSourceInfo;
}

public Pair<BootstrapSourceInfo, HoodieWriteStat> getBootstrapSourceAndWriteStat() {
return Pair.of(getBootstrapSourceInfo(), getStat());
}

public void setBootstrapSourceInfo(BootstrapSourceInfo bootstrapSourceInfo) {
this.bootstrapSourceInfo = bootstrapSourceInfo;
}
}
Loading