Search in sources :

Example 6 with IndexClient

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

the class TestIndexCacheLoader method testNoLastModifiedTime.

@Test(expectedExceptions = Exception.class)
public void testNoLastModifiedTime() throws Exception {
    IndexClient indexclient = mock(IndexClient.class);
    IndexCacheLoader indexCacheLoader = new IndexCacheLoader(indexclient);
    IndexCacheKey indexCacheKey = new IndexCacheKey("/path/to/split", 1);
    // throw exception to produce "no last modified time file found" behaviour
    when(indexclient.getLastModifiedTime((indexCacheKey.getPath()))).thenThrow(Exception.class);
    indexCacheLoader.load(indexCacheKey);
}
Also used : IndexClient(io.prestosql.spi.heuristicindex.IndexClient) IndexCacheKey(io.prestosql.spi.heuristicindex.IndexCacheKey) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 7 with IndexClient

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

the class TestIndexCacheLoader method testNoValidIndexFilesFoundException.

@Test(expectedExceptions = Exception.class)
public void testNoValidIndexFilesFoundException() throws Exception {
    IndexClient indexclient = mock(IndexClient.class);
    IndexCacheLoader indexCacheLoader = new IndexCacheLoader(indexclient);
    long lastModifiedTime = 1L;
    IndexCacheKey indexCacheKey = new IndexCacheKey("/path/to/split", lastModifiedTime);
    when(indexclient.getLastModifiedTime((indexCacheKey.getPath()))).thenReturn(lastModifiedTime);
    when(indexclient.readSplitIndex((indexCacheKey.getPath()))).thenThrow(Exception.class);
    indexCacheLoader.load(indexCacheKey);
}
Also used : IndexClient(io.prestosql.spi.heuristicindex.IndexClient) IndexCacheKey(io.prestosql.spi.heuristicindex.IndexCacheKey) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 8 with IndexClient

use of io.prestosql.spi.heuristicindex.IndexClient in project boostkit-bigdata by kunpengcompute.

the class TestIndexCacheLoader method testNoMatchingLastModifiedTime.

@Test(expectedExceptions = Exception.class)
public void testNoMatchingLastModifiedTime() throws Exception {
    IndexClient indexclient = mock(IndexClient.class);
    IndexCacheLoader indexCacheLoader = new IndexCacheLoader(indexclient);
    IndexCacheKey indexCacheKey = new IndexCacheKey("/path/to/split", 1L);
    // return different last modified time to simulate expired index
    when(indexclient.getLastModifiedTime((indexCacheKey.getPath()))).thenReturn(2L);
    indexCacheLoader.load(indexCacheKey);
}
Also used : IndexClient(io.prestosql.spi.heuristicindex.IndexClient) IndexCacheKey(io.prestosql.spi.heuristicindex.IndexCacheKey) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 9 with IndexClient

use of io.prestosql.spi.heuristicindex.IndexClient in project boostkit-bigdata by kunpengcompute.

the class TestIndexCacheLoader method testNoValidIndexFilesFound.

@Test(expectedExceptions = Exception.class)
public void testNoValidIndexFilesFound() throws Exception {
    IndexClient indexclient = mock(IndexClient.class);
    IndexCacheLoader indexCacheLoader = new IndexCacheLoader(indexclient);
    long lastModifiedTime = 1L;
    IndexCacheKey indexCacheKey = new IndexCacheKey("/path/to/split", lastModifiedTime);
    when(indexclient.getLastModifiedTime((indexCacheKey.getPath()))).thenReturn(lastModifiedTime);
    when(indexclient.readSplitIndex((indexCacheKey.getPath()))).thenReturn(Collections.emptyList());
    indexCacheLoader.load(indexCacheKey);
}
Also used : IndexClient(io.prestosql.spi.heuristicindex.IndexClient) IndexCacheKey(io.prestosql.spi.heuristicindex.IndexCacheKey) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 10 with IndexClient

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

the class DropIndexTask method execute.

@Override
public ListenableFuture<?> execute(DropIndex statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
    IndexClient indexClient = heuristicIndexerManager.getIndexClient();
    String indexName = statement.getIndexName().toString();
    try {
        IndexRecord record = indexClient.lookUpIndexRecord(indexName);
        // check indexName exist, call heuristic index api to drop index
        if (record == null) {
            throw new SemanticException(MISSING_INDEX, statement, "Index '%s' does not exist", indexName);
        }
        QualifiedObjectName fullObjectName = QualifiedObjectName.valueOf(record.qualifiedTable);
        Session session = stateMachine.getSession();
        accessControl.checkCanDropIndex(session.getRequiredTransactionId(), session.getIdentity(), fullObjectName);
        List<String> partitions = Collections.emptyList();
        if (statement.getPartitions().isPresent()) {
            partitions = HeuristicIndexUtils.extractPartitions(statement.getPartitions().get());
            List<String> partitionsInindex = indexClient.lookUpIndexRecord(indexName).partitions;
            if (partitionsInindex.isEmpty()) {
                throw new SemanticException(MISSING_INDEX, statement, "Index '%s' was not created with explicit partitions. Partial drop by partition is not supported.", indexName);
            }
            List<String> missingPartitions = new ArrayList<>(partitions);
            missingPartitions.removeAll(partitionsInindex);
            if (!missingPartitions.isEmpty()) {
                throw new SemanticException(MISSING_INDEX, statement, "Index '%s' does not contain partitions: %s", indexName, missingPartitions);
            }
        }
        indexClient.deleteIndex(indexName, partitions);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return immediateFuture(null);
}
Also used : IndexClient(io.prestosql.spi.heuristicindex.IndexClient) ArrayList(java.util.ArrayList) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) IndexRecord(io.prestosql.spi.heuristicindex.IndexRecord) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) SemanticException(io.prestosql.sql.analyzer.SemanticException) Session(io.prestosql.Session)

Aggregations

IndexClient (io.prestosql.spi.heuristicindex.IndexClient)19 IndexCacheKey (io.prestosql.spi.heuristicindex.IndexCacheKey)16 BeforeTest (org.testng.annotations.BeforeTest)15 Test (org.testng.annotations.Test)15 IndexMetadata (io.prestosql.spi.heuristicindex.IndexMetadata)4 IOException (java.io.IOException)4 LinkedList (java.util.LinkedList)4 UncheckedIOException (java.io.UncheckedIOException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 IndexRecord (io.prestosql.spi.heuristicindex.IndexRecord)2 IndexWriter (io.prestosql.spi.heuristicindex.IndexWriter)2 ArrayList (java.util.ArrayList)2 CacheLoader (com.google.common.cache.CacheLoader)1 ImmutableList (com.google.common.collect.ImmutableList)1 Sets (com.google.common.collect.Sets)1 Logger (io.airlift.log.Logger)1 Duration (io.airlift.units.Duration)1 Session (io.prestosql.Session)1 SqlStageExecution (io.prestosql.execution.SqlStageExecution)1