Search in sources :

Example 31 with HoodieException

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

the class HoodieDLAClient method createDLAConnection.

private void createDLAConnection() {
    if (connection == null) {
        try {
            Class.forName(DRIVER_NAME);
        } catch (ClassNotFoundException e) {
            LOG.error("Unable to load DLA driver class", e);
            return;
        }
        try {
            this.connection = DriverManager.getConnection(dlaConfig.jdbcUrl, dlaConfig.dlaUser, dlaConfig.dlaPass);
            LOG.info("Successfully established DLA connection to  " + dlaConfig.jdbcUrl);
        } catch (SQLException e) {
            throw new HoodieException("Cannot create dla connection ", e);
        }
    }
}
Also used : SQLException(java.sql.SQLException) HoodieException(org.apache.hudi.exception.HoodieException)

Example 32 with HoodieException

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

the class HoodieDLAClient method getTableSchema.

public Map<String, String> getTableSchema(String tableName) {
    if (!doesTableExist(tableName)) {
        throw new IllegalArgumentException("Failed to get schema for table " + tableName + " does not exist");
    }
    Map<String, String> schema = new HashMap<>();
    ResultSet result = null;
    try {
        DatabaseMetaData databaseMetaData = connection.getMetaData();
        result = databaseMetaData.getColumns(dlaConfig.databaseName, dlaConfig.databaseName, tableName, null);
        while (result.next()) {
            TYPE_CONVERTOR.doConvert(result, schema);
        }
        return schema;
    } catch (SQLException e) {
        throw new HoodieException("Failed to get table schema for " + tableName, e);
    } finally {
        closeQuietly(result, null);
    }
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) HoodieException(org.apache.hudi.exception.HoodieException) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 33 with HoodieException

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

the class TimestampBasedAvroKeyGenerator method getPartitionPath.

/**
 * Parse and fetch partition path based on data type.
 *
 * @param partitionVal partition path object value fetched from record/row
 * @return the parsed partition path based on data type
 */
public String getPartitionPath(Object partitionVal) {
    initIfNeeded();
    long timeMs;
    if (partitionVal instanceof Double) {
        timeMs = convertLongTimeToMillis(((Double) partitionVal).longValue());
    } else if (partitionVal instanceof Float) {
        timeMs = convertLongTimeToMillis(((Float) partitionVal).longValue());
    } else if (partitionVal instanceof Long) {
        timeMs = convertLongTimeToMillis((Long) partitionVal);
    } else if (partitionVal instanceof Timestamp && isConsistentLogicalTimestampEnabled()) {
        timeMs = ((Timestamp) partitionVal).getTime();
    } else if (partitionVal instanceof Integer) {
        timeMs = convertLongTimeToMillis(((Integer) partitionVal).longValue());
    } else if (partitionVal instanceof BigDecimal) {
        timeMs = convertLongTimeToMillis(((BigDecimal) partitionVal).longValue());
    } else if (partitionVal instanceof CharSequence) {
        if (!inputFormatter.isPresent()) {
            throw new HoodieException("Missing inputformatter. Ensure " + KeyGeneratorOptions.Config.TIMESTAMP_INPUT_DATE_FORMAT_PROP + " config is set when timestampType is DATE_STRING or MIXED!");
        }
        DateTime parsedDateTime = inputFormatter.get().parseDateTime(partitionVal.toString());
        if (this.outputDateTimeZone == null) {
            // Use the timezone that came off the date that was passed in, if it had one
            partitionFormatter = partitionFormatter.withZone(parsedDateTime.getZone());
        }
        timeMs = inputFormatter.get().parseDateTime(partitionVal.toString()).getMillis();
    } else {
        throw new HoodieNotSupportedException("Unexpected type for partition field: " + partitionVal.getClass().getName());
    }
    DateTime timestamp = new DateTime(timeMs, outputDateTimeZone);
    String partitionPath = timestamp.toString(partitionFormatter);
    if (encodePartitionPath) {
        partitionPath = PartitionPathEncodeUtils.escapePathName(partitionPath);
    }
    return hiveStylePartitioning ? getPartitionPathFields().get(0) + "=" + partitionPath : partitionPath;
}
Also used : HoodieException(org.apache.hudi.exception.HoodieException) HoodieNotSupportedException(org.apache.hudi.exception.HoodieNotSupportedException) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) DateTime(org.joda.time.DateTime)

Example 34 with HoodieException

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

the class HoodieBackedTableMetadataWriter method initTableMetadata.

public void initTableMetadata() {
    try {
        if (this.metadata != null) {
            this.metadata.close();
        }
        this.metadata = new HoodieBackedTableMetadata(engineContext, dataWriteConfig.getMetadataConfig(), dataWriteConfig.getBasePath(), dataWriteConfig.getSpillableMapBasePath());
        this.metadataMetaClient = metadata.getMetadataMetaClient();
    } catch (Exception e) {
        throw new HoodieException("Error initializing metadata table for reads", e);
    }
}
Also used : HoodieException(org.apache.hudi.exception.HoodieException) HoodieException(org.apache.hudi.exception.HoodieException) IOException(java.io.IOException) HoodieMetadataException(org.apache.hudi.exception.HoodieMetadataException)

Example 35 with HoodieException

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

the class HoodieBackedTableMetadataWriter method enablePartitions.

/**
 * Enable metadata table partitions based on config.
 */
private void enablePartitions() {
    final HoodieMetadataConfig metadataConfig = dataWriteConfig.getMetadataConfig();
    boolean isBootstrapCompleted;
    Option<HoodieTableMetaClient> metaClient = Option.empty();
    try {
        isBootstrapCompleted = dataMetaClient.getFs().exists(new Path(metadataWriteConfig.getBasePath(), HoodieTableMetaClient.METAFOLDER_NAME));
        if (isBootstrapCompleted) {
            metaClient = Option.of(HoodieTableMetaClient.builder().setConf(hadoopConf.get()).setBasePath(metadataWriteConfig.getBasePath()).build());
        }
    } catch (IOException e) {
        throw new HoodieException("Failed to enable metadata partitions!", e);
    }
    Option<HoodieTableFileSystemView> fsView = Option.ofNullable(metaClient.isPresent() ? HoodieTableMetadataUtil.getFileSystemView(metaClient.get()) : null);
    enablePartition(MetadataPartitionType.FILES, metadataConfig, metaClient, fsView, isBootstrapCompleted);
    if (metadataConfig.isBloomFilterIndexEnabled()) {
        enablePartition(MetadataPartitionType.BLOOM_FILTERS, metadataConfig, metaClient, fsView, isBootstrapCompleted);
    }
    if (metadataConfig.isColumnStatsIndexEnabled()) {
        enablePartition(MetadataPartitionType.COLUMN_STATS, metadataConfig, metaClient, fsView, isBootstrapCompleted);
    }
}
Also used : HoodieTableMetaClient(org.apache.hudi.common.table.HoodieTableMetaClient) Path(org.apache.hadoop.fs.Path) HoodieMetadataConfig(org.apache.hudi.common.config.HoodieMetadataConfig) HoodieException(org.apache.hudi.exception.HoodieException) IOException(java.io.IOException) HoodieTableFileSystemView(org.apache.hudi.common.table.view.HoodieTableFileSystemView)

Aggregations

HoodieException (org.apache.hudi.exception.HoodieException)171 IOException (java.io.IOException)87 Path (org.apache.hadoop.fs.Path)45 Schema (org.apache.avro.Schema)35 HoodieIOException (org.apache.hudi.exception.HoodieIOException)35 List (java.util.List)30 ArrayList (java.util.ArrayList)27 HoodieTableMetaClient (org.apache.hudi.common.table.HoodieTableMetaClient)23 Collectors (java.util.stream.Collectors)21 HoodieInstant (org.apache.hudi.common.table.timeline.HoodieInstant)19 Option (org.apache.hudi.common.util.Option)19 HoodieTimeline (org.apache.hudi.common.table.timeline.HoodieTimeline)18 Map (java.util.Map)16 HoodieRecord (org.apache.hudi.common.model.HoodieRecord)16 GenericRecord (org.apache.avro.generic.GenericRecord)15 Arrays (java.util.Arrays)14 HoodieLogFile (org.apache.hudi.common.model.HoodieLogFile)14 Logger (org.apache.log4j.Logger)14 FileStatus (org.apache.hadoop.fs.FileStatus)13 HoodieCommitMetadata (org.apache.hudi.common.model.HoodieCommitMetadata)13