use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class AbstractTestQueries method testExecuteWithParametersInGroupBy.
@Test
public void testExecuteWithParametersInGroupBy() {
try {
String query = "SELECT a + ?, count(1) FROM (VALUES 1, 2, 3, 2) t(a) GROUP BY a + ?";
Session session = Session.builder(getSession()).addPreparedStatement("my_query", query).build();
computeActual(session, "EXECUTE my_query USING 1, 1");
fail("parameters in GROUP BY and SELECT should fail");
} catch (SemanticException e) {
assertEquals(e.getCode(), MUST_BE_AGGREGATE_OR_GROUP_BY);
} catch (RuntimeException e) {
assertEquals(e.getMessage(), "line 1:10: '(a + ?)' must be an aggregate expression or appear in GROUP BY clause");
}
}
use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class UseTask method execute.
@Override
public ListenableFuture<?> execute(Use statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
Session session = stateMachine.getSession();
// This section of code loads the dc sub catalogs
DataCenterUtility.loadDCCatalogForUseTask(statement, metadata, session);
if (!statement.getCatalog().isPresent() && !session.getCatalog().isPresent()) {
throw new SemanticException(CATALOG_NOT_SPECIFIED, statement, "Catalog must be specified when session catalog is not set");
}
if (statement.getCatalog().isPresent()) {
String catalog = statement.getCatalog().get().getValue().toLowerCase(ENGLISH);
if (!metadata.getCatalogHandle(session, catalog).isPresent()) {
throw new PrestoException(NOT_FOUND, "Catalog does not exist: " + catalog);
}
stateMachine.setSetCatalog(catalog);
}
// Fix accepting nonexistent schema name in USE <schema> command
validateSchema(metadata, session, statement);
stateMachine.setSetSchema(statement.getSchema().getValue().toLowerCase(ENGLISH));
return immediateFuture(null);
}
use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class MetadataUtil method createQualifiedObjectName.
public static QualifiedObjectName createQualifiedObjectName(Session session, Node node, QualifiedName name) {
requireNonNull(session, "session is null");
requireNonNull(name, "name is null");
// Hetu supports cluster so that there can be 4 dots in <cluster>.<catalog>.<schema>.<table>
if (name.getParts().size() > 4) {
throw new PrestoException(SYNTAX_ERROR, format("Too many dots in table name: %s", name));
}
List<String> parts = Lists.reverse(name.getParts());
String objectName = parts.get(0);
String schemaName = (parts.size() > 1) ? parts.get(1) : session.getSchema().orElseThrow(() -> new SemanticException(SCHEMA_NOT_SPECIFIED, node, "Schema must be specified when session schema is not set"));
String catalogName;
// If there are 4 dots, combine the first two components into one and use it as catalog
if (parts.size() > 3) {
catalogName = (parts.size() > 3) ? parts.get(3) + "." + parts.get(2) : session.getCatalog().orElseThrow(() -> new SemanticException(CATALOG_NOT_SPECIFIED, node, "Catalog must be specified when session catalog is not set"));
} else {
catalogName = (parts.size() > 2) ? parts.get(2) : session.getCatalog().orElseThrow(() -> new SemanticException(CATALOG_NOT_SPECIFIED, node, "Catalog must be specified when session catalog is not set"));
}
return new QualifiedObjectName(catalogName, schemaName, objectName);
}
use of io.prestosql.sql.analyzer.SemanticException 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);
}
use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class ExpressionInterpreter method evaluateConstantExpression.
public static Object evaluateConstantExpression(Expression expression, Type expectedType, Metadata metadata, Session session, List<Expression> parameters) {
ExpressionAnalyzer analyzer = createConstantAnalyzer(metadata, session, parameters, WarningCollector.NOOP);
analyzer.analyze(expression, Scope.create());
Type actualType = analyzer.getExpressionTypes().get(NodeRef.of(expression));
if (!new TypeCoercion(metadata::getType).canCoerce(actualType, expectedType)) {
throw new SemanticException(SemanticErrorCode.TYPE_MISMATCH, expression, String.format("Cannot cast type %s to %s", actualType.getTypeSignature(), expectedType.getTypeSignature()));
}
Map<NodeRef<Expression>, Type> coercions = ImmutableMap.<NodeRef<Expression>, Type>builder().putAll(analyzer.getExpressionCoercions()).put(NodeRef.of(expression), expectedType).build();
return evaluateConstantExpression(expression, coercions, analyzer.getTypeOnlyCoercions(), metadata, session, ImmutableSet.of(), parameters);
}
Aggregations