private Response failQuery(QueryId queryId, PrestoException queryException) { requireNonNull(queryId, "queryId is null"); try { QueryState state = queryManager.getQueryState(queryId); // check before killing to provide the proper error code (this is racy) if (state.isDone()) { return Response.status(Status.CONFLICT).build(); } queryManager.failQuery(queryId, queryException); // verify if the query was failed (if not, we lost the race) if (!queryException.getErrorCode().equals(queryManager.getQueryInfo(queryId).getErrorCode())) { return Response.status(Status.CONFLICT).build(); } return Response.status(Status.OK).build(); } catch (NoSuchElementException e) { return Response.status(Status.GONE).build(); } }
@ScalarOperator(CAST) @SqlNullable @SqlType(TINYINT) public static Long castToTinyint(@SqlType(JSON) Slice json) { try (JsonParser parser = createJsonParser(JSON_FACTORY, json)) { parser.nextToken(); Long result = currentTokenAsTinyint(parser); checkCondition(parser.nextToken() == null, INVALID_CAST_ARGUMENT, "Cannot cast input json to TINYINT"); // check no trailing token return result; } catch (PrestoException e) { if (e.getErrorCode().equals(NUMERIC_VALUE_OUT_OF_RANGE.toErrorCode())) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to %s", json.toStringUtf8(), INTEGER), e.getCause()); } throw e; } catch (IllegalArgumentException | IOException | JsonCastException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to %s", json.toStringUtf8(), TINYINT), e); } }
@ScalarOperator(CAST) @SqlNullable @SqlType(SMALLINT) public static Long castToSmallint(@SqlType(JSON) Slice json) { try (JsonParser parser = createJsonParser(JSON_FACTORY, json)) { parser.nextToken(); Long result = currentTokenAsSmallint(parser); checkCondition(parser.nextToken() == null, INVALID_CAST_ARGUMENT, "Cannot cast input json to SMALLINT"); // check no trailing token return result; } catch (PrestoException e) { if (e.getErrorCode().equals(NUMERIC_VALUE_OUT_OF_RANGE.toErrorCode())) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to %s", json.toStringUtf8(), INTEGER), e.getCause()); } throw e; } catch (IllegalArgumentException | IOException | JsonCastException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to %s", json.toStringUtf8(), SMALLINT), e); } }
@ScalarOperator(CAST) @SqlNullable @SqlType(INTEGER) public static Long castToInteger(@SqlType(JSON) Slice json) { try (JsonParser parser = createJsonParser(JSON_FACTORY, json)) { parser.nextToken(); Long result = currentTokenAsInteger(parser); checkCondition(parser.nextToken() == null, INVALID_CAST_ARGUMENT, "Cannot cast input json to INTEGER"); // check no trailing token return result; } catch (PrestoException e) { if (e.getErrorCode().equals(NUMERIC_VALUE_OUT_OF_RANGE.toErrorCode())) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to %s", json.toStringUtf8(), INTEGER), e.getCause()); } throw e; } catch (ArithmeticException | IOException | JsonCastException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to %s", json.toStringUtf8(), INTEGER), e); } }
private PartitionStatistics getExistingPartitionStatistics(Partition partition, String partitionName) { try { PartitionStatistics statistics = delegate.getPartitionStatistics(partition.getDatabaseName(), partition.getTableName(), ImmutableSet.of(partitionName)) .get(partitionName); if (statistics == null) { throw new PrestoException( TRANSACTION_CONFLICT, format("The partition that this transaction modified was deleted in another transaction. %s %s", partition.getTableName(), partition.getValues())); } return statistics; } catch (PrestoException e) { if (e.getErrorCode().equals(HIVE_CORRUPTED_COLUMN_STATISTICS.toErrorCode())) { log.warn( e, "Corrupted statistics found when altering partition. Table: %s.%s. Partition: %s", partition.getDatabaseName(), partition.getTableName(), partition.getValues()); return PartitionStatistics.empty(); } throw e; } }
if (!e.getErrorCode().equals(ALREADY_EXISTS.toErrorCode()) || !statement.isNotExists()) { throw e;
@Override public TableStatistics getTableStatistics( ConnectorSession session, SchemaTableName table, Map<String, ColumnHandle> columns, Map<String, Type> columnTypes, List<HivePartition> partitions) { if (!isStatisticsEnabled(session)) { return TableStatistics.empty(); } if (partitions.isEmpty()) { return createZeroStatistics(columns, columnTypes); } int sampleSize = getPartitionStatisticsSampleSize(session); List<HivePartition> partitionsSample = getPartitionsSample(partitions, sampleSize); try { Map<String, PartitionStatistics> statisticsSample = statisticsProvider.getPartitionsStatistics(table, partitionsSample); validatePartitionStatistics(table, statisticsSample); return getTableStatistics(columns, columnTypes, partitions, statisticsSample); } catch (PrestoException e) { if (e.getErrorCode().equals(HIVE_CORRUPTED_COLUMN_STATISTICS.toErrorCode()) && isIgnoreCorruptedStatistics(session)) { log.error(e); return TableStatistics.empty(); } throw e; } }
@UsedByGeneratedCode public void killQuery(String queryId, String message) { QueryId query = parseQueryId(queryId); try { QueryState state = queryManager.getQueryState(query); // check before killing to provide the proper error message (this is racy) if (state.isDone()) { throw new PrestoException(NOT_SUPPORTED, "Target query is not running: " + queryId); } queryManager.failQuery(query, createKillQueryException(message)); // verify if the query was killed (if not, we lost the race) if (!ADMINISTRATIVELY_KILLED.toErrorCode().equals(queryManager.getQueryInfo(query).getErrorCode())) { throw new PrestoException(NOT_SUPPORTED, "Target query is not running: " + queryId); } } catch (NoSuchElementException e) { throw new PrestoException(NOT_FOUND, "Target query not found: " + queryId); } }
public abstract class AdBlockerListener implements AdListener { @Override public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) { if (arg1.equals(ErrorCode.NETWORK_ERROR)) { try { URL url = new URL("http://www.apple.com/"); URLConnection conn = url.openConnection(); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); reader.readLine(); onAdBlocked(); } catch (IOException e) {} } } public abstract void onAdBlocked(); }
public <V> V run(Supplier<V> supplier) { try (TimeStat.BlockTimer ignored = time.time()) { V value = supplier.get(); successes.update(1); return value; } catch (PrestoException e) { if (e.getErrorCode().equals(RAPTOR_BACKUP_NOT_FOUND.toErrorCode())) { successes.update(1); } else if (e.getErrorCode().equals(RAPTOR_BACKUP_TIMEOUT.toErrorCode())) { timeouts.update(1); } else { failures.update(1); } throw e; } } }