Search in sources :

Example 1 with PrestoTransportException

use of io.prestosql.spi.PrestoTransportException in project hetu-core by openlookeng.

the class Failures method toFailure.

private static ExecutionFailureInfo toFailure(Throwable throwable, Set<Throwable> seenFailures) {
    if (throwable == null) {
        return null;
    }
    String type;
    HostAddress remoteHost = null;
    SemanticErrorCode semanticErrorCode = null;
    if (throwable instanceof Failure) {
        type = ((Failure) throwable).getType();
    } else {
        Class<?> clazz = throwable.getClass();
        type = firstNonNull(clazz.getCanonicalName(), clazz.getName());
    }
    if (throwable instanceof PrestoTransportException) {
        remoteHost = ((PrestoTransportException) throwable).getRemoteHost();
    }
    if (throwable instanceof SemanticException) {
        semanticErrorCode = ((SemanticException) throwable).getCode();
    }
    if (seenFailures.contains(throwable)) {
        return new ExecutionFailureInfo(type, "[cyclic] " + throwable.getMessage(), null, ImmutableList.of(), ImmutableList.of(), null, GENERIC_INTERNAL_ERROR.toErrorCode(), Optional.ofNullable(semanticErrorCode), remoteHost);
    }
    seenFailures.add(throwable);
    ExecutionFailureInfo cause = toFailure(throwable.getCause(), seenFailures);
    ErrorCode errorCode = toErrorCode(throwable);
    if (errorCode == null) {
        if (cause == null) {
            errorCode = GENERIC_INTERNAL_ERROR.toErrorCode();
        } else {
            errorCode = cause.getErrorCode();
        }
    }
    return new ExecutionFailureInfo(type, throwable.getMessage(), cause, Arrays.stream(throwable.getSuppressed()).map(failure -> toFailure(failure, seenFailures)).collect(toImmutableList()), Lists.transform(asList(throwable.getStackTrace()), toStringFunction()), getErrorLocation(throwable), errorCode, Optional.ofNullable(semanticErrorCode), remoteHost);
}
Also used : SemanticErrorCode(io.prestosql.sql.analyzer.SemanticErrorCode) ErrorCode(io.prestosql.spi.ErrorCode) StandardErrorCode(io.prestosql.spi.StandardErrorCode) HostAddress(io.prestosql.spi.HostAddress) SemanticErrorCode(io.prestosql.sql.analyzer.SemanticErrorCode) PrestoTransportException(io.prestosql.spi.PrestoTransportException) Failure(io.prestosql.execution.Failure) SemanticException(io.prestosql.sql.analyzer.SemanticException) ExecutionFailureInfo(io.prestosql.execution.ExecutionFailureInfo)

Example 2 with PrestoTransportException

use of io.prestosql.spi.PrestoTransportException in project hetu-core by openlookeng.

the class DataCenterClient method getTableStatistics.

/**
 * Get remote table statistics.
 *
 * @param tableFullName the fully qualified table name
 * @param columnHandles data center column handles
 * @return the table statistics
 */
public TableStatistics getTableStatistics(String tableFullName, Map<String, ColumnHandle> columnHandles) {
    String query = "SHOW STATS FOR " + tableFullName;
    Iterable<List<Object>> data;
    try {
        data = getResults(clientSession, query);
    } catch (SQLException ex) {
        throw new PrestoTransportException(REMOTE_TASK_ERROR, HostAddress.fromUri(this.serverUri.uri()), "could not connect to the remote data center");
    }
    TableStatistics.Builder builder = TableStatistics.builder();
    List<Object> lastRow = null;
    for (List<Object> row : data) {
        ColumnStatistics.Builder columnStatisticBuilder = new ColumnStatistics.Builder();
        lastRow = row;
        if (row.get(0) == null) {
            // Only the last row can have the first column (column name) null
            continue;
        }
        // row[0] is column_name
        DataCenterColumnHandle columnHandle = (DataCenterColumnHandle) columnHandles.get(row.get(0).toString());
        if (columnHandle == null) {
            // Unknown column found
            continue;
        }
        // row[1] is data_size
        if (row.get(1) != null) {
            columnStatisticBuilder.setDataSize(Estimate.of(Double.parseDouble(row.get(1).toString())));
        }
        // row[2] is distinct_values_count
        if (row.get(2) != null) {
            columnStatisticBuilder.setDistinctValuesCount(Estimate.of(Double.parseDouble(row.get(2).toString())));
        }
        // row[3] is nulls_fraction
        if (row.get(3) != null) {
            columnStatisticBuilder.setNullsFraction(Estimate.of(Double.parseDouble(row.get(3).toString())));
        }
        // row[5] is low_value and row[6] is high_value
        if (row.get(5) != null && row.get(6) != null) {
            String minStr = row.get(5).toString();
            String maxStr = row.get(6).toString();
            Type columnType = columnHandle.getColumnType();
            if (columnType.equals(DATE)) {
                LocalDate minDate = LocalDate.parse(minStr, DATE_FORMATTER);
                LocalDate maxDate = LocalDate.parse(maxStr, DATE_FORMATTER);
                columnStatisticBuilder.setRange(new DoubleRange(minDate.toEpochDay(), maxDate.toEpochDay()));
            } else {
                columnStatisticBuilder.setRange(new DoubleRange(Double.parseDouble(minStr), Double.parseDouble(maxStr)));
            }
        }
        builder.setColumnStatistics(columnHandle, columnStatisticBuilder.build());
    }
    // Get row_count from the last row
    if (lastRow != null && lastRow.get(4) != null) {
        builder.setRowCount(Estimate.of(Double.parseDouble(lastRow.get(4).toString())));
    }
    return builder.build();
}
Also used : ColumnStatistics(io.prestosql.spi.statistics.ColumnStatistics) SQLException(java.sql.SQLException) LocalDate(java.time.LocalDate) DoubleRange(io.prestosql.spi.statistics.DoubleRange) Type(io.prestosql.spi.type.Type) TypeUtil.parseType(io.prestosql.client.util.TypeUtil.parseType) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) TableStatistics(io.prestosql.spi.statistics.TableStatistics) PrestoTransportException(io.prestosql.spi.PrestoTransportException) DataCenterColumnHandle(io.hetu.core.plugin.datacenter.DataCenterColumnHandle)

Example 3 with PrestoTransportException

use of io.prestosql.spi.PrestoTransportException in project hetu-core by openlookeng.

the class ConnectorManager method addCatalogConnector.

/**
 * Hetu requires this method to treat DC Connectors differently from other connectors.
 *
 * @param catalogName the catalog name
 * @param factory the connector factory
 * @param properties catalog properties
 * @param checkConnection check whether connection of catalog is available.
 */
private synchronized void addCatalogConnector(CatalogName catalogName, ConnectorFactory factory, Map<String, String> properties, boolean checkConnection) {
    // create all connectors before adding, so a broken connector does not leave the system half updated
    // Hetu reads the DC Connector properties file and dynamically creates <data-center>.<catalog-name> catalogs for each catalogs in that data center
    Connector catalogConnector = createConnector(catalogName, factory, properties);
    if (DATA_CENTER_CONNECTOR_NAME.equals(factory.getName())) {
        // It registers the Connector and Properties in the DataCenterConnectorStore
        catalogConnectorStore.registerConnectorAndProperties(catalogName, catalogConnector, properties);
        if (checkConnection) {
            // check connection
            String catalog = catalogName.getCatalogName();
            Connector connector = catalogConnectorStore.getCatalogConnector(catalog);
            try {
                connector.getCatalogs(properties.get(CONNECTION_USER), properties);
            } catch (PrestoTransportException e) {
                throw new PrestoException(REMOTE_TASK_ERROR, "Failed to get catalogs from remote data center.");
            }
        }
    } else {
        addCatalogConnector(catalogName, catalogConnector);
    }
}
Also used : Connector(io.prestosql.spi.connector.Connector) InformationSchemaConnector(io.prestosql.connector.informationschema.InformationSchemaConnector) SystemConnector(io.prestosql.connector.system.SystemConnector) PrestoException(io.prestosql.spi.PrestoException) PrestoTransportException(io.prestosql.spi.PrestoTransportException)

Example 4 with PrestoTransportException

use of io.prestosql.spi.PrestoTransportException in project hetu-core by openlookeng.

the class DataCenterConnectorManager method loadAllDCCatalogs.

/**
 * Hetu DC requires the method to load all the DC subcatalog. The method is called
 * while execution of 'show catalogs' query
 */
public void loadAllDCCatalogs() {
    boolean needUpdateConnectionIds = false;
    synchronized (this) {
        List<String> dataCenterNames = catalogConnectorStore.getDataCenterNames();
        for (String dataCenterName : dataCenterNames) {
            try {
                Connector catalogConnector = catalogConnectorStore.getCatalogConnector(dataCenterName);
                Map<String, String> properties = catalogConnectorStore.getCatalogProperties(dataCenterName);
                Set<String> remoteSubCatalogs = Sets.newHashSet(catalogConnector.getCatalogs(properties.get(CONNECTION_USER), properties));
                // availableCatalogs is the List of all dc sub catalogs stored in Hetu
                Set<String> availableCatalogs = catalogConnectorStore.getSubCatalogs(dataCenterName);
                // which is not available in Hetu
                for (String subCatalog : remoteSubCatalogs) {
                    if (!catalogConnectorStore.containsSubCatalog(dataCenterName, subCatalog)) {
                        addSubCatalog(dataCenterName, subCatalog, properties);
                        needUpdateConnectionIds = true;
                    }
                }
                // is not available in remote Hetu dc
                for (String availableCatalog : availableCatalogs) {
                    if (!remoteSubCatalogs.contains(availableCatalog)) {
                        deleteSubCatalog(dataCenterName, availableCatalog);
                        needUpdateConnectionIds = true;
                    }
                }
            } catch (PrestoTransportException ignore) {
                log.warn(ignore, "Load the catalogs of data center %s failed.", dataCenterName);
            }
        }
    }
    if (needUpdateConnectionIds) {
        connectorManager.updateConnectorIds();
    }
}
Also used : Connector(io.prestosql.spi.connector.Connector) PrestoTransportException(io.prestosql.spi.PrestoTransportException)

Example 5 with PrestoTransportException

use of io.prestosql.spi.PrestoTransportException in project hetu-core by openlookeng.

the class DataCenterClient method getCatalogNames.

/**
 * Get catalogs from the remote data center.
 *
 * @return the catalogs
 */
public Set<String> getCatalogNames() {
    String query = "SELECT * FROM SYSTEM.METADATA.CATALOGS";
    try {
        Set<String> catalogNames = new HashSet<>();
        Iterable<List<Object>> data = getResults(clientSession, query);
        for (List<Object> row : data) {
            String catalogName = row.get(0).toString();
            // Skip remote dc catalogs to avoid cyclic dependency
            if (!catalogName.contains(SPLIT_DOT)) {
                catalogNames.add(catalogName);
            }
        }
        return catalogNames;
    } catch (SQLException ex) {
        throw new PrestoTransportException(REMOTE_TASK_ERROR, HostAddress.fromUri(this.serverUri.uri()), "could not connect to the data center");
    }
}
Also used : SQLException(java.sql.SQLException) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) PrestoTransportException(io.prestosql.spi.PrestoTransportException) HashSet(java.util.HashSet)

Aggregations

PrestoTransportException (io.prestosql.spi.PrestoTransportException)6 ImmutableList (com.google.common.collect.ImmutableList)2 PrestoException (io.prestosql.spi.PrestoException)2 Connector (io.prestosql.spi.connector.Connector)2 SQLException (java.sql.SQLException)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 DataCenterColumnHandle (io.hetu.core.plugin.datacenter.DataCenterColumnHandle)1 TypeUtil.parseType (io.prestosql.client.util.TypeUtil.parseType)1 InformationSchemaConnector (io.prestosql.connector.informationschema.InformationSchemaConnector)1 SystemConnector (io.prestosql.connector.system.SystemConnector)1 ExecutionFailureInfo (io.prestosql.execution.ExecutionFailureInfo)1 Failure (io.prestosql.execution.Failure)1 ErrorCode (io.prestosql.spi.ErrorCode)1 HostAddress (io.prestosql.spi.HostAddress)1 StandardErrorCode (io.prestosql.spi.StandardErrorCode)1 ColumnStatistics (io.prestosql.spi.statistics.ColumnStatistics)1 DoubleRange (io.prestosql.spi.statistics.DoubleRange)1 TableStatistics (io.prestosql.spi.statistics.TableStatistics)1 Type (io.prestosql.spi.type.Type)1