Search in sources :

Example 31 with SemanticException

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);
}
Also used : QualifiedName(io.prestosql.sql.tree.QualifiedName) PrestoException(io.prestosql.spi.PrestoException) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) MetadataUtil.createQualifiedObjectName(io.prestosql.metadata.MetadataUtil.createQualifiedObjectName) Session(io.prestosql.Session) SemanticException(io.prestosql.sql.analyzer.SemanticException)

Example 32 with SemanticException

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();
}
Also used : PrestoException(io.prestosql.spi.PrestoException) ImmutableMap(com.google.common.collect.ImmutableMap) PrestoException(io.prestosql.spi.PrestoException) SemanticException(io.prestosql.sql.analyzer.SemanticException) ExpressionInterpreter.evaluateConstantExpression(io.prestosql.sql.planner.ExpressionInterpreter.evaluateConstantExpression) Expression(io.prestosql.sql.tree.Expression) PropertyMetadata(io.prestosql.spi.session.PropertyMetadata) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) SemanticException(io.prestosql.sql.analyzer.SemanticException)

Example 33 with SemanticException

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"));
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) SemanticException(io.prestosql.sql.analyzer.SemanticException) Test(org.testng.annotations.Test)

Example 34 with SemanticException

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);
    }
}
Also used : DropCache(io.prestosql.sql.tree.DropCache) AllowAllAccessControl(io.prestosql.security.AllowAllAccessControl) HeuristicIndexerManager(io.prestosql.heuristicindex.HeuristicIndexerManager) HetuMetaStoreManager(io.prestosql.metastore.HetuMetaStoreManager) FileSystemClientManager(io.prestosql.filesystem.FileSystemClientManager) SemanticException(io.prestosql.sql.analyzer.SemanticException) Test(org.testng.annotations.Test)

Aggregations

SemanticException (io.prestosql.sql.analyzer.SemanticException)34 Session (io.prestosql.Session)27 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)16 MetadataUtil.createQualifiedObjectName (io.prestosql.metadata.MetadataUtil.createQualifiedObjectName)14 PrestoException (io.prestosql.spi.PrestoException)13 TableHandle (io.prestosql.spi.metadata.TableHandle)11 Expression (io.prestosql.sql.tree.Expression)8 CubeMetaStore (io.hetu.core.spi.cube.io.CubeMetaStore)7 CatalogName (io.prestosql.spi.connector.CatalogName)7 HeuristicIndexerManager (io.prestosql.heuristicindex.HeuristicIndexerManager)6 Futures.immediateFuture (com.google.common.util.concurrent.Futures.immediateFuture)5 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 Metadata (io.prestosql.metadata.Metadata)5 AccessControl (io.prestosql.security.AccessControl)5 Type (io.prestosql.spi.type.Type)5 TransactionManager (io.prestosql.transaction.TransactionManager)5 List (java.util.List)5 Map (java.util.Map)4 Optional (java.util.Optional)4 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)3