Search in sources :

Example 76 with HoodieIOException

use of org.apache.hudi.exception.HoodieIOException in project hudi by apache.

the class HoodieTestDataGenerator method generateUpdatesForAllRecords.

/**
 * Generate update for each record in the dataset.
 * @param instantTime
 * @return
 * @throws IOException
 */
public List<HoodieRecord> generateUpdatesForAllRecords(String instantTime) {
    List<HoodieRecord> updates = new ArrayList<>();
    Map<Integer, KeyPartition> existingKeys = existingKeysBySchema.get(TRIP_EXAMPLE_SCHEMA);
    existingKeys.values().forEach(kp -> {
        try {
            HoodieRecord record = generateUpdateRecord(kp.key, instantTime);
            updates.add(record);
        } catch (IOException ioe) {
            throw new HoodieIOException(ioe.getMessage(), ioe);
        }
    });
    return updates;
}
Also used : HoodieIOException(org.apache.hudi.exception.HoodieIOException) HoodieRecord(org.apache.hudi.common.model.HoodieRecord) ArrayList(java.util.ArrayList) IOException(java.io.IOException) HoodieIOException(org.apache.hudi.exception.HoodieIOException)

Example 77 with HoodieIOException

use of org.apache.hudi.exception.HoodieIOException in project hudi by apache.

the class HoodieTestDataGenerator method generateInsertsStream.

/**
 * Generates new inserts, uniformly across the partition paths above. It also updates the list of existing keys.
 */
public Stream<HoodieRecord> generateInsertsStream(String instantTime, Integer n, boolean isFlattened, String schemaStr, boolean containsAllPartitions, Supplier<String> partitionPathSupplier, Supplier<String> recordKeySupplier) {
    int currSize = getNumExistingKeys(schemaStr);
    return IntStream.range(0, n).boxed().map(i -> {
        String partitionPath = partitionPathSupplier.get();
        if (containsAllPartitions && i < partitionPaths.length) {
            partitionPath = partitionPaths[i];
        }
        HoodieKey key = new HoodieKey(recordKeySupplier.get(), partitionPath);
        KeyPartition kp = new KeyPartition();
        kp.key = key;
        kp.partitionPath = partitionPath;
        populateKeysBySchema(schemaStr, currSize + i, kp);
        incrementNumExistingKeysBySchema(schemaStr);
        try {
            return new HoodieAvroRecord(key, generateRandomValueAsPerSchema(schemaStr, key, instantTime, isFlattened));
        } catch (IOException e) {
            throw new HoodieIOException(e.getMessage(), e);
        }
    });
}
Also used : HoodieIOException(org.apache.hudi.exception.HoodieIOException) HoodieAvroRecord(org.apache.hudi.common.model.HoodieAvroRecord) HoodieKey(org.apache.hudi.common.model.HoodieKey) IOException(java.io.IOException) HoodieIOException(org.apache.hudi.exception.HoodieIOException)

Example 78 with HoodieIOException

use of org.apache.hudi.exception.HoodieIOException in project hudi by apache.

the class HoodieTestTable method getMetadataForInstant.

private Option<HoodieCommitMetadata> getMetadataForInstant(String instantTime) {
    metaClient = HoodieTableMetaClient.reload(metaClient);
    Option<HoodieInstant> hoodieInstant = metaClient.getActiveTimeline().getCommitsTimeline().filterCompletedInstants().filter(i -> i.getTimestamp().equals(instantTime)).firstInstant();
    try {
        if (hoodieInstant.isPresent()) {
            return getCommitMeta(hoodieInstant.get());
        } else {
            return Option.empty();
        }
    } catch (IOException io) {
        throw new HoodieIOException("Unable to read metadata for instant " + hoodieInstant.get(), io);
    }
}
Also used : HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) Arrays(java.util.Arrays) REPLACE_COMMIT_ACTION(org.apache.hudi.common.table.timeline.HoodieTimeline.REPLACE_COMMIT_ACTION) FileSystem(org.apache.hadoop.fs.FileSystem) Date(java.util.Date) HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) FileCreateUtils.createDeltaCommit(org.apache.hudi.common.testutils.FileCreateUtils.createDeltaCommit) Random(java.util.Random) FileCreateUtils.createRestoreFile(org.apache.hudi.common.testutils.FileCreateUtils.createRestoreFile) FileStatus(org.apache.hadoop.fs.FileStatus) FileCreateUtils.createMarkerFile(org.apache.hudi.common.testutils.FileCreateUtils.createMarkerFile) HoodieSavepointMetadata(org.apache.hudi.avro.model.HoodieSavepointMetadata) Logger(org.apache.log4j.Logger) HoodieTableType(org.apache.hudi.common.model.HoodieTableType) CLEAN_ACTION(org.apache.hudi.common.table.timeline.HoodieTimeline.CLEAN_ACTION) FileCreateUtils.createInflightCommit(org.apache.hudi.common.testutils.FileCreateUtils.createInflightCommit) HoodieTableConfig(org.apache.hudi.common.table.HoodieTableConfig) CleanPlanV2MigrationHandler(org.apache.hudi.common.table.timeline.versioning.clean.CleanPlanV2MigrationHandler) Map(java.util.Map) HoodieRollbackMetadata(org.apache.hudi.avro.model.HoodieRollbackMetadata) Path(org.apache.hadoop.fs.Path) FileCreateUtils.createReplaceCommit(org.apache.hudi.common.testutils.FileCreateUtils.createReplaceCommit) FileCreateUtils.createInflightCompaction(org.apache.hudi.common.testutils.FileCreateUtils.createInflightCompaction) FileCreateUtils.logFileName(org.apache.hudi.common.testutils.FileCreateUtils.logFileName) HoodieActiveTimeline(org.apache.hudi.common.table.timeline.HoodieActiveTimeline) FileCreateUtils.createRequestedReplaceCommit(org.apache.hudi.common.testutils.FileCreateUtils.createRequestedReplaceCommit) ValidationUtils(org.apache.hudi.common.util.ValidationUtils) CollectionUtils.createImmutableMap(org.apache.hudi.common.util.CollectionUtils.createImmutableMap) CleanerUtils.convertCleanMetadata(org.apache.hudi.common.util.CleanerUtils.convertCleanMetadata) HoodieCleanerPlan(org.apache.hudi.avro.model.HoodieCleanerPlan) IOType(org.apache.hudi.common.model.IOType) TimelineMetadataUtils(org.apache.hudi.common.table.timeline.TimelineMetadataUtils) FileCreateUtils.createRollbackFile(org.apache.hudi.common.testutils.FileCreateUtils.createRollbackFile) HoodieRollbackPlan(org.apache.hudi.avro.model.HoodieRollbackPlan) UUID(java.util.UUID) COMPACT(org.apache.hudi.common.model.WriteOperationType.COMPACT) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) HoodieFileFormat(org.apache.hudi.common.model.HoodieFileFormat) List(java.util.List) Stream(java.util.stream.Stream) FileCreateUtils.createRequestedCommit(org.apache.hudi.common.testutils.FileCreateUtils.createRequestedCommit) CommitUtils.getCommitActionType(org.apache.hudi.common.util.CommitUtils.getCommitActionType) HoodieWriteStat(org.apache.hudi.common.model.HoodieWriteStat) HoodieCompactionPlan(org.apache.hudi.avro.model.HoodieCompactionPlan) HoodieRestoreMetadata(org.apache.hudi.avro.model.HoodieRestoreMetadata) HoodieSavepointPartitionMetadata(org.apache.hudi.avro.model.HoodieSavepointPartitionMetadata) WriteOperationType(org.apache.hudi.common.model.WriteOperationType) FileCreateUtils.createRequestedCompaction(org.apache.hudi.common.testutils.FileCreateUtils.createRequestedCompaction) CompactionUtils(org.apache.hudi.common.util.CompactionUtils) IntStream(java.util.stream.IntStream) HoodieCleaningPolicy(org.apache.hudi.common.model.HoodieCleaningPolicy) FileCreateUtils.createInflightRollbackFile(org.apache.hudi.common.testutils.FileCreateUtils.createInflightRollbackFile) FileCreateUtils.createInflightCleanFile(org.apache.hudi.common.testutils.FileCreateUtils.createInflightCleanFile) FileSlice(org.apache.hudi.common.model.FileSlice) FileCreateUtils.createRequestedDeltaCommit(org.apache.hudi.common.testutils.FileCreateUtils.createRequestedDeltaCommit) Option(org.apache.hudi.common.util.Option) HashMap(java.util.HashMap) FileCreateUtils.createRequestedCleanFile(org.apache.hudi.common.testutils.FileCreateUtils.createRequestedCleanFile) FileCreateUtils.baseFileName(org.apache.hudi.common.testutils.FileCreateUtils.baseFileName) ArrayList(java.util.ArrayList) FileCreateUtils.createInflightReplaceCommit(org.apache.hudi.common.testutils.FileCreateUtils.createInflightReplaceCommit) FileCreateUtils.createInflightDeltaCommit(org.apache.hudi.common.testutils.FileCreateUtils.createInflightDeltaCommit) HoodieRequestedReplaceMetadata(org.apache.hudi.avro.model.HoodieRequestedReplaceMetadata) HoodieTableMetaClient(org.apache.hudi.common.table.HoodieTableMetaClient) HoodieRollbackPartitionMetadata(org.apache.hudi.avro.model.HoodieRollbackPartitionMetadata) HoodieTimeline(org.apache.hudi.common.table.timeline.HoodieTimeline) HoodieCleanStat(org.apache.hudi.common.HoodieCleanStat) SECONDS(java.time.temporal.ChronoUnit.SECONDS) CommitUtils.buildMetadata(org.apache.hudi.common.util.CommitUtils.buildMetadata) FileCreateUtils.createCleanFile(org.apache.hudi.common.testutils.FileCreateUtils.createCleanFile) Files(java.nio.file.Files) MERGE_ON_READ(org.apache.hudi.common.model.HoodieTableType.MERGE_ON_READ) EMPTY_STRING(org.apache.hudi.common.util.StringUtils.EMPTY_STRING) HoodieCommitMetadata(org.apache.hudi.common.model.HoodieCommitMetadata) IOException(java.io.IOException) FileCreateUtils.createRequestedRollbackFile(org.apache.hudi.common.testutils.FileCreateUtils.createRequestedRollbackFile) HoodieInstantInfo(org.apache.hudi.avro.model.HoodieInstantInfo) HoodieActionInstant(org.apache.hudi.avro.model.HoodieActionInstant) HoodieReplaceCommitMetadata(org.apache.hudi.common.model.HoodieReplaceCommitMetadata) HoodieCleanMetadata(org.apache.hudi.avro.model.HoodieCleanMetadata) Paths(java.nio.file.Paths) HoodiePartitionMetadata(org.apache.hudi.common.model.HoodiePartitionMetadata) CLUSTER(org.apache.hudi.common.model.WriteOperationType.CLUSTER) FileCreateUtils.createCommit(org.apache.hudi.common.testutils.FileCreateUtils.createCommit) HoodieIOException(org.apache.hudi.exception.HoodieIOException) LogManager(org.apache.log4j.LogManager) Comparator(java.util.Comparator) Collections(java.util.Collections) UPSERT(org.apache.hudi.common.model.WriteOperationType.UPSERT) FSUtils(org.apache.hudi.common.fs.FSUtils) Pair(org.apache.hudi.common.util.collection.Pair) HoodieIOException(org.apache.hudi.exception.HoodieIOException) IOException(java.io.IOException) HoodieIOException(org.apache.hudi.exception.HoodieIOException)

Example 79 with HoodieIOException

use of org.apache.hudi.exception.HoodieIOException in project hudi by apache.

the class SchemaTestUtil method toRecords.

private static <T extends IndexedRecord> List<T> toRecords(Schema writerSchema, Schema readerSchema, int from, int limit) throws IOException, URISyntaxException {
    GenericDatumReader<T> reader = new GenericDatumReader<>(writerSchema, readerSchema);
    Path dataPath = initializeSampleDataPath();
    try (Stream<String> stream = Files.lines(dataPath)) {
        return stream.skip(from).limit(limit).map(s -> {
            try {
                return reader.read(null, DecoderFactory.get().jsonDecoder(writerSchema, s));
            } catch (IOException e) {
                throw new HoodieIOException("Could not read data from " + RESOURCE_SAMPLE_DATA, e);
            }
        }).collect(Collectors.toList());
    } catch (IOException e) {
        throw new HoodieIOException("Could not read data from " + RESOURCE_SAMPLE_DATA, e);
    }
}
Also used : Path(java.nio.file.Path) HoodieAvroPayload(org.apache.hudi.common.model.HoodieAvroPayload) GenericArray(org.apache.avro.generic.GenericArray) HoodieAvroUtils(org.apache.hudi.avro.HoodieAvroUtils) URISyntaxException(java.net.URISyntaxException) Option(org.apache.hudi.common.util.Option) HashMap(java.util.HashMap) Random(java.util.Random) ByteBuffer(java.nio.ByteBuffer) GenericData(org.apache.avro.generic.GenericData) ArrayList(java.util.ArrayList) Map(java.util.Map) URI(java.net.URI) Path(java.nio.file.Path) HoodieActiveTimeline(org.apache.hudi.common.table.timeline.HoodieActiveTimeline) IndexedRecord(org.apache.avro.generic.IndexedRecord) HoodieRecord(org.apache.hudi.common.model.HoodieRecord) Utf8(org.apache.avro.util.Utf8) GenericRecord(org.apache.avro.generic.GenericRecord) Schema(org.apache.avro.Schema) Iterator(java.util.Iterator) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) Files(java.nio.file.Files) IOException(java.io.IOException) UUID(java.util.UUID) FileSystem(java.nio.file.FileSystem) Collectors(java.util.stream.Collectors) HoodieAvroRecord(org.apache.hudi.common.model.HoodieAvroRecord) List(java.util.List) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) HoodieKey(org.apache.hudi.common.model.HoodieKey) HoodieIOException(org.apache.hudi.exception.HoodieIOException) GenericDatumReader(org.apache.avro.generic.GenericDatumReader) DecoderFactory(org.apache.avro.io.DecoderFactory) FileSystems(java.nio.file.FileSystems) MercifulJsonConverter(org.apache.hudi.avro.MercifulJsonConverter) HoodieIOException(org.apache.hudi.exception.HoodieIOException) GenericDatumReader(org.apache.avro.generic.GenericDatumReader) IOException(java.io.IOException) HoodieIOException(org.apache.hudi.exception.HoodieIOException)

Example 80 with HoodieIOException

use of org.apache.hudi.exception.HoodieIOException in project hudi by apache.

the class HoodieCommonTestHarness method initPath.

/**
 * Initializes basePath.
 */
protected void initPath() {
    try {
        java.nio.file.Path basePath = tempDir.resolve("dataset");
        java.nio.file.Files.createDirectories(basePath);
        this.basePath = basePath.toString();
    } catch (IOException ioe) {
        throw new HoodieIOException(ioe.getMessage(), ioe);
    }
}
Also used : HoodieIOException(org.apache.hudi.exception.HoodieIOException) HoodieIOException(org.apache.hudi.exception.HoodieIOException) IOException(java.io.IOException)

Aggregations

HoodieIOException (org.apache.hudi.exception.HoodieIOException)139 IOException (java.io.IOException)127 Path (org.apache.hadoop.fs.Path)45 List (java.util.List)31 ArrayList (java.util.ArrayList)30 Option (org.apache.hudi.common.util.Option)27 Collectors (java.util.stream.Collectors)26 HoodieInstant (org.apache.hudi.common.table.timeline.HoodieInstant)26 Pair (org.apache.hudi.common.util.collection.Pair)25 LogManager (org.apache.log4j.LogManager)25 Logger (org.apache.log4j.Logger)25 Map (java.util.Map)21 FileSystem (org.apache.hadoop.fs.FileSystem)20 GenericRecord (org.apache.avro.generic.GenericRecord)19 HashSet (java.util.HashSet)18 HoodieRecord (org.apache.hudi.common.model.HoodieRecord)18 HoodieTableMetaClient (org.apache.hudi.common.table.HoodieTableMetaClient)18 Set (java.util.Set)17 HoodieTimeline (org.apache.hudi.common.table.timeline.HoodieTimeline)17 HoodieException (org.apache.hudi.exception.HoodieException)17