use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class DropCacheTask method execute.
@Override
public ListenableFuture<?> execute(DropCache statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
if (!PropertyService.getBooleanProperty(HetuConstant.SPLIT_CACHE_MAP_ENABLED)) {
throw new PrestoException(GENERIC_USER_ERROR, "Cache table feature is not enabled");
}
Session session = stateMachine.getSession();
QualifiedObjectName fullObjectName = createQualifiedObjectName(session, statement, statement.getTableName());
QualifiedName tableName = QualifiedName.of(fullObjectName.getCatalogName(), fullObjectName.getSchemaName(), fullObjectName.getObjectName());
SplitCacheMap splitCacheMap = SplitCacheMap.getInstance();
// Check if split cache has predicates for the requested table
if (!splitCacheMap.cacheExists(tableName)) {
throw new SemanticException(MISSING_CACHE, statement, "Cache for table '%s' does not exist", tableName.toString());
}
splitCacheMap.dropCache(tableName, statement.getWhere().map(Expression::toString));
return immediateFuture(null);
}
use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class AbstractPropertyManager method getProperties.
public final Map<String, Object> getProperties(CatalogName catalogName, // only use this for error messages
String catalog, Map<String, Expression> sqlPropertyValues, Session session, Metadata metadata, List<Expression> parameters) {
Map<String, PropertyMetadata<?>> supportedProperties = connectorProperties.get(catalogName);
if (supportedProperties == null) {
throw new PrestoException(NOT_FOUND, "Catalog not found: " + catalog);
}
ImmutableMap.Builder<String, Object> properties = ImmutableMap.builder();
// Fill in user-specified properties
for (Map.Entry<String, Expression> sqlProperty : sqlPropertyValues.entrySet()) {
String propertyName = sqlProperty.getKey().toLowerCase(ENGLISH);
PropertyMetadata<?> property = supportedProperties.get(propertyName);
if (property == null) {
throw new PrestoException(propertyError, format("Catalog '%s' does not support %s property '%s'", catalog, propertyType, propertyName));
}
Object sqlObjectValue;
try {
sqlObjectValue = evaluatePropertyValue(sqlProperty.getValue(), property.getSqlType(), session, metadata, parameters);
} catch (SemanticException e) {
throw new PrestoException(propertyError, format("Invalid value for %s property '%s': Cannot convert [%s] to %s", propertyType, property.getName(), sqlProperty.getValue(), property.getSqlType()), e);
}
Object value;
try {
value = property.decode(sqlObjectValue);
} catch (Exception e) {
throw new PrestoException(propertyError, format("Unable to set %s property '%s' to [%s]: %s", propertyType, property.getName(), sqlProperty.getValue(), e.getMessage()), e);
}
properties.put(property.getName(), value);
}
Map<String, Object> userSpecifiedProperties = properties.build();
// Fill in the remaining properties with non-null defaults
for (PropertyMetadata<?> propertyMetadata : supportedProperties.values()) {
if (!userSpecifiedProperties.containsKey(propertyMetadata.getName())) {
Object value = propertyMetadata.getDefaultValue();
if (value != null) {
properties.put(propertyMetadata.getName(), value);
}
}
}
return properties.build();
}
use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class TestArrayOperators method testSubscript.
@Test
public void testSubscript() {
String outOfBounds = "Array subscript out of bounds";
String negativeIndex = "Array subscript is negative";
String indexIsZero = "SQL array indices start at 1";
assertInvalidFunction("ARRAY [][1]", outOfBounds);
assertInvalidFunction("ARRAY [null][-1]", negativeIndex);
assertInvalidFunction("ARRAY [1, 2, 3][0]", indexIsZero);
assertInvalidFunction("ARRAY [1, 2, 3][-1]", negativeIndex);
assertInvalidFunction("ARRAY [1, 2, 3][4]", outOfBounds);
try {
assertFunction("ARRAY [1, 2, 3][1.1E0]", BIGINT, null);
fail("Access to array with double subscript should fail");
} catch (SemanticException e) {
assertTrue(e.getCode() == TYPE_MISMATCH);
}
assertFunction("ARRAY[NULL][1]", UNKNOWN, null);
assertFunction("ARRAY[NULL, NULL, NULL][3]", UNKNOWN, null);
assertFunction("1 + ARRAY [2, 1, 3][2]", INTEGER, 2);
assertFunction("ARRAY [2, 1, 3][2]", INTEGER, 1);
assertFunction("ARRAY [2, NULL, 3][2]", INTEGER, null);
assertFunction("ARRAY [1.0E0, 2.5E0, 3.5E0][3]", DOUBLE, 3.5);
assertFunction("ARRAY [ARRAY[1, 2], ARRAY[3]][2]", new ArrayType(INTEGER), ImmutableList.of(3));
assertFunction("ARRAY [ARRAY[1, 2], NULL, ARRAY[3]][2]", new ArrayType(INTEGER), null);
assertFunction("ARRAY [ARRAY[1, 2], ARRAY[3]][2][1]", INTEGER, 3);
assertFunction("ARRAY ['puppies', 'kittens'][2]", createVarcharType(7), "kittens");
assertFunction("ARRAY ['puppies', 'kittens', NULL][3]", createVarcharType(7), null);
assertFunction("ARRAY [TRUE, FALSE][2]", BOOLEAN, false);
assertFunction("ARRAY [TIMESTAMP '1970-01-01 00:00:01', TIMESTAMP '1973-07-08 22:00:01'][1]", TIMESTAMP, sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0));
assertFunction("ARRAY [infinity()][1]", DOUBLE, POSITIVE_INFINITY);
assertFunction("ARRAY [-infinity()][1]", DOUBLE, NEGATIVE_INFINITY);
assertFunction("ARRAY [sqrt(-1)][1]", DOUBLE, NaN);
assertDecimalFunction("ARRAY [2.1, 2.2, 2.3][3]", decimal("2.3"));
assertDecimalFunction("ARRAY [2.111111222111111114111, 2.22222222222222222, 2.222222222222223][3]", decimal("2.222222222222223000000"));
assertDecimalFunction("ARRAY [1.9, 2, 2.3][3]", decimal("0000000002.3"));
assertDecimalFunction("ARRAY [2.22222222222222222, 2.3][1]", decimal("2.22222222222222222"));
}
use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class TestDropCacheTask method testDropCacheNotExistsFalse.
@Test
public void testDropCacheNotExistsFalse() {
DropCache statement = new DropCache(QualifiedName.of("test_nonexistent_table"), false);
QueryStateMachine queryStateMachine = createQueryStateMachine("START TRANSACTION", testSession, transactionManager);
try {
getFutureValue(new DropCacheTask().execute(statement, createTestTransactionManager(), metadata, new AllowAllAccessControl(), queryStateMachine, Collections.emptyList(), new HeuristicIndexerManager(new FileSystemClientManager(), new HetuMetaStoreManager())));
fail("expected exception");
} catch (RuntimeException e) {
// Expected
assertTrue(e instanceof SemanticException);
SemanticException semanticException = (SemanticException) e;
assertEquals(semanticException.getCode(), SemanticErrorCode.MISSING_CACHE);
}
}
Aggregations