-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: James Sun <[email protected]>
- Loading branch information
1 parent
398a38e
commit 0cd9fb1
Showing
4 changed files
with
267 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
presto-hive/src/main/java/com/facebook/presto/hive/HiveEmptySplitPageSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.hive; | ||
|
||
import com.facebook.presto.common.Page; | ||
import com.facebook.presto.spi.ConnectorPageSource; | ||
|
||
public class HiveEmptySplitPageSource | ||
implements ConnectorPageSource | ||
{ | ||
@Override | ||
public long getCompletedBytes() | ||
{ | ||
return 0; | ||
} | ||
|
||
@Override | ||
public long getCompletedPositions() | ||
{ | ||
return 0; | ||
} | ||
|
||
@Override | ||
public long getReadTimeNanos() | ||
{ | ||
return 0; | ||
} | ||
|
||
@Override | ||
public boolean isFinished() | ||
{ | ||
return true; | ||
} | ||
|
||
@Override | ||
public Page getNextPage() | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public long getSystemMemoryUsage() | ||
{ | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void close() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
171 changes: 171 additions & 0 deletions
171
presto-hive/src/test/java/com/facebook/presto/hive/TestDynamicBucketPruning.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.hive; | ||
|
||
import com.facebook.airlift.testing.TempFile; | ||
import com.facebook.presto.common.predicate.Domain; | ||
import com.facebook.presto.common.predicate.TupleDomain; | ||
import com.facebook.presto.common.type.StandardTypes; | ||
import com.facebook.presto.hive.metastore.Column; | ||
import com.facebook.presto.hive.metastore.Storage; | ||
import com.facebook.presto.hive.metastore.StorageFormat; | ||
import com.facebook.presto.spi.ColumnHandle; | ||
import com.facebook.presto.spi.ConnectorId; | ||
import com.facebook.presto.spi.ConnectorPageSource; | ||
import com.facebook.presto.spi.SchemaTableName; | ||
import com.facebook.presto.spi.SplitContext; | ||
import com.facebook.presto.spi.TableHandle; | ||
import com.facebook.presto.testing.TestingConnectorSession; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Optional; | ||
import java.util.OptionalInt; | ||
|
||
import static com.facebook.presto.common.type.IntegerType.INTEGER; | ||
import static com.facebook.presto.common.type.TypeSignature.parseTypeSignature; | ||
import static com.facebook.presto.expressions.LogicalRowExpressions.TRUE_CONSTANT; | ||
import static com.facebook.presto.hive.BucketFunctionType.HIVE_COMPATIBLE; | ||
import static com.facebook.presto.hive.CacheQuotaRequirement.NO_CACHE_REQUIREMENT; | ||
import static com.facebook.presto.hive.HiveColumnHandle.ColumnType.REGULAR; | ||
import static com.facebook.presto.hive.HiveQueryRunner.HIVE_CATALOG; | ||
import static com.facebook.presto.hive.HiveTestUtils.ROW_EXPRESSION_SERVICE; | ||
import static com.facebook.presto.hive.HiveTestUtils.TYPE_MANAGER; | ||
import static com.facebook.presto.hive.HiveTestUtils.createTestHdfsEnvironment; | ||
import static com.facebook.presto.hive.HiveTestUtils.getDefaultHiveBatchPageSourceFactories; | ||
import static com.facebook.presto.hive.HiveTestUtils.getDefaultHiveRecordCursorProvider; | ||
import static com.facebook.presto.hive.HiveTestUtils.getDefaultHiveSelectivePageSourceFactories; | ||
import static com.facebook.presto.hive.HiveType.HIVE_INT; | ||
import static com.facebook.presto.hive.TestHivePageSink.getColumnHandles; | ||
import static com.facebook.presto.spi.schedule.NodeSelectionStrategy.NO_PREFERENCE; | ||
import static com.google.common.collect.ImmutableList.toImmutableList; | ||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.fail; | ||
|
||
public class TestDynamicBucketPruning | ||
{ | ||
private static final String SCHEMA_NAME = "test"; | ||
private static final String TABLE_NAME = "test"; | ||
private static final Column BUCKET_COLUMN = new Column("l_orderkey", HIVE_INT, Optional.empty()); | ||
|
||
@Test | ||
public void testDynamicBucketPruning() | ||
{ | ||
HiveClientConfig config = new HiveClientConfig(); | ||
MetastoreClientConfig metastoreClientConfig = new MetastoreClientConfig(); | ||
HiveTransactionHandle transaction = new HiveTransactionHandle(); | ||
try (TempFile tempFile = new TempFile()) { | ||
ConnectorPageSource emptyPageSource = createTestingPageSource(transaction, config, new SplitContext(false, getToSkipTupleDomain()), metastoreClientConfig, tempFile.file()); | ||
assertEquals(emptyPageSource.getClass(), HiveEmptySplitPageSource.class); | ||
|
||
ConnectorPageSource nonEmptyPageSource = createTestingPageSource(transaction, config, new SplitContext(false, getToKeepTupleDomain()), metastoreClientConfig, tempFile.file()); | ||
assertEquals(nonEmptyPageSource.getClass(), HivePageSource.class); | ||
} | ||
catch (IOException e) { | ||
e.printStackTrace(); | ||
fail(); | ||
} | ||
} | ||
|
||
private static ConnectorPageSource createTestingPageSource(HiveTransactionHandle transaction, HiveClientConfig config, SplitContext splitContext, MetastoreClientConfig metastoreClientConfig, File outputFile) | ||
{ | ||
HiveSplit split = new HiveSplit( | ||
SCHEMA_NAME, | ||
TABLE_NAME, | ||
"", | ||
"file:///" + outputFile.getAbsolutePath(), | ||
0, | ||
outputFile.length(), | ||
outputFile.length(), | ||
new Storage( | ||
StorageFormat.create(config.getHiveStorageFormat().getSerDe(), config.getHiveStorageFormat().getInputFormat(), config.getHiveStorageFormat().getOutputFormat()), | ||
"location", | ||
Optional.of(new HiveBucketProperty(ImmutableList.of("l_orderkey"), 10, ImmutableList.of(), HIVE_COMPATIBLE, Optional.empty())), | ||
false, | ||
ImmutableMap.of(), | ||
ImmutableMap.of()), | ||
ImmutableList.of(), | ||
ImmutableList.of(), | ||
OptionalInt.of(1), | ||
OptionalInt.of(1), | ||
NO_PREFERENCE, | ||
getColumnHandles().size(), | ||
ImmutableMap.of(), | ||
Optional.empty(), | ||
false, | ||
Optional.empty(), | ||
NO_CACHE_REQUIREMENT, | ||
Optional.empty(), | ||
ImmutableMap.of()); | ||
|
||
TableHandle tableHandle = new TableHandle( | ||
new ConnectorId(HIVE_CATALOG), | ||
new HiveTableHandle(SCHEMA_NAME, TABLE_NAME), | ||
transaction, | ||
Optional.of(new HiveTableLayoutHandle( | ||
new SchemaTableName(SCHEMA_NAME, TABLE_NAME), | ||
ImmutableList.of(), | ||
getColumnHandles().stream() | ||
.map(column -> new Column(column.getName(), column.getHiveType(), Optional.empty())) | ||
.collect(toImmutableList()), | ||
ImmutableMap.of(), | ||
TupleDomain.all(), | ||
TRUE_CONSTANT, | ||
ImmutableMap.of(), | ||
TupleDomain.all(), | ||
Optional.empty(), | ||
Optional.empty(), | ||
false, | ||
"layout", | ||
Optional.empty()))); | ||
HivePageSourceProvider provider = new HivePageSourceProvider(config, createTestHdfsEnvironment(config, metastoreClientConfig), getDefaultHiveRecordCursorProvider(config, metastoreClientConfig), getDefaultHiveBatchPageSourceFactories(config, metastoreClientConfig), getDefaultHiveSelectivePageSourceFactories(config, metastoreClientConfig), TYPE_MANAGER, ROW_EXPRESSION_SERVICE); | ||
return provider.createPageSource(transaction, getSession(config), split, tableHandle.getLayout().get(), ImmutableList.copyOf(getColumnHandles()), splitContext); | ||
} | ||
|
||
private static TupleDomain<ColumnHandle> getToSkipTupleDomain() | ||
{ | ||
return TupleDomain.withColumnDomains( | ||
ImmutableMap.of( | ||
new HiveColumnHandle( | ||
BUCKET_COLUMN.getName(), | ||
BUCKET_COLUMN.getType(), | ||
parseTypeSignature(StandardTypes.VARCHAR), | ||
0, | ||
REGULAR, | ||
Optional.empty()), | ||
Domain.singleValue(INTEGER, 10L))); | ||
} | ||
|
||
private static TupleDomain<ColumnHandle> getToKeepTupleDomain() | ||
{ | ||
return TupleDomain.withColumnDomains( | ||
ImmutableMap.of( | ||
new HiveColumnHandle( | ||
BUCKET_COLUMN.getName(), | ||
BUCKET_COLUMN.getType(), | ||
parseTypeSignature(StandardTypes.VARCHAR), | ||
0, | ||
REGULAR, | ||
Optional.empty()), | ||
Domain.singleValue(INTEGER, 1L))); | ||
} | ||
|
||
private static TestingConnectorSession getSession(HiveClientConfig config) | ||
{ | ||
return new TestingConnectorSession(new HiveSessionProperties(config, new OrcFileWriterConfig(), new ParquetFileWriterConfig()).getSessionProperties()); | ||
} | ||
} |