use of org.apache.druid.segment.QueryableIndexSegment in project druid by druid-io.
the class BaseHashJoinSegmentStorageAdapterTest method setUp.
@Before
public void setUp() throws IOException {
factSegment = new QueryableIndexSegment(JoinTestHelper.createFactIndexBuilder(temporaryFolder.newFolder()).buildMMappedIndex(), SegmentId.dummy("facts"));
countryIsoCodeToNameLookup = JoinTestHelper.createCountryIsoCodeToNameLookup();
countryNumberToNameLookup = JoinTestHelper.createCountryNumberToNameLookup();
countriesTable = JoinTestHelper.createCountriesIndexedTable();
regionsTable = JoinTestHelper.createRegionsIndexedTable();
}
use of org.apache.druid.segment.QueryableIndexSegment in project druid by druid-io.
the class HashJoinSegmentTest method setUp.
@Before
public void setUp() throws IOException {
allReferencesAcquireCount = 0;
allReferencesCloseCount = 0;
referencedSegmentAcquireCount = 0;
referencedSegmentClosedCount = 0;
indexedTableJoinableReferenceAcquireCount = 0;
indexedTableJoinableReferenceCloseCount = 0;
j0Closed = false;
j1Closed = false;
baseSegment = new QueryableIndexSegment(JoinTestHelper.createFactIndexBuilder(temporaryFolder.newFolder()).buildMMappedIndex(), SegmentId.dummy("facts"));
List<JoinableClause> joinableClauses = ImmutableList.of(new JoinableClause("j0.", new IndexedTableJoinable(JoinTestHelper.createCountriesIndexedTable()) {
@Override
public Optional<Closeable> acquireReferences() {
if (!j0Closed) {
indexedTableJoinableReferenceAcquireCount++;
Closer closer = Closer.create();
closer.register(() -> indexedTableJoinableReferenceCloseCount++);
return Optional.of(closer);
}
return Optional.empty();
}
}, JoinType.LEFT, JoinConditionAnalysis.forExpression("1", "j0.", ExprMacroTable.nil())), new JoinableClause("j1.", new IndexedTableJoinable(JoinTestHelper.createRegionsIndexedTable()) {
@Override
public Optional<Closeable> acquireReferences() {
if (!j1Closed) {
indexedTableJoinableReferenceAcquireCount++;
Closer closer = Closer.create();
closer.register(() -> indexedTableJoinableReferenceCloseCount++);
return Optional.of(closer);
}
return Optional.empty();
}
}, JoinType.LEFT, JoinConditionAnalysis.forExpression("1", "j1.", ExprMacroTable.nil())));
referencedSegment = ReferenceCountingSegment.wrapRootGenerationSegment(baseSegment);
SegmentReference testWrapper = new SegmentReference() {
@Override
public Optional<Closeable> acquireReferences() {
Closer closer = Closer.create();
return referencedSegment.acquireReferences().map(closeable -> {
referencedSegmentAcquireCount++;
closer.register(closeable);
closer.register(() -> referencedSegmentClosedCount++);
return closer;
});
}
@Override
public SegmentId getId() {
return referencedSegment.getId();
}
@Override
public Interval getDataInterval() {
return referencedSegment.getDataInterval();
}
@Nullable
@Override
public QueryableIndex asQueryableIndex() {
return referencedSegment.asQueryableIndex();
}
@Override
public StorageAdapter asStorageAdapter() {
return referencedSegment.asStorageAdapter();
}
@Override
public void close() {
referencedSegment.close();
}
};
hashJoinSegment = new HashJoinSegment(testWrapper, null, joinableClauses, null) {
@Override
public Optional<Closeable> acquireReferences() {
Closer closer = Closer.create();
return super.acquireReferences().map(closeable -> {
allReferencesAcquireCount++;
closer.register(closeable);
closer.register(() -> allReferencesCloseCount++);
return closer;
});
}
};
}
use of org.apache.druid.segment.QueryableIndexSegment in project druid by druid-io.
the class SpecificSegmentsQuerySegmentWalker method add.
public SpecificSegmentsQuerySegmentWalker add(final DataSegment descriptor, final QueryableIndex index) {
final ReferenceCountingSegment segment = ReferenceCountingSegment.wrapSegment(new QueryableIndexSegment(index, descriptor.getId()), descriptor.getShardSpec());
final VersionedIntervalTimeline<String, ReferenceCountingSegment> timeline = timelines.computeIfAbsent(descriptor.getDataSource(), datasource -> new VersionedIntervalTimeline<>(Ordering.natural()));
timeline.add(descriptor.getInterval(), descriptor.getVersion(), descriptor.getShardSpec().createChunk(segment));
segments.add(descriptor);
closeables.add(segment);
return this;
}
use of org.apache.druid.segment.QueryableIndexSegment in project druid by druid-io.
the class DoubleStorageTest method testSelectValues.
@Test
public void testSelectValues() {
QueryRunner runner = QueryRunnerTestHelper.makeQueryRunner(SCAN_QUERY_RUNNER_FACTORY, SEGMENT_ID, new QueryableIndexSegment(index, SEGMENT_ID), null);
ScanQuery query = newTestQuery().intervals(new LegacySegmentSpec(INTERVAL)).virtualColumns().build();
Iterable<ScanResultValue> results = runner.run(QueryPlus.wrap(query)).toList();
ScanResultValue expectedScanResult = new ScanResultValue(SEGMENT_ID.toString(), ImmutableList.of(TIME_COLUMN, DIM_NAME, DIM_FLOAT_NAME), getStreamOfEvents().collect(Collectors.toList()));
List<ScanResultValue> expectedResults = Collections.singletonList(expectedScanResult);
ScanQueryRunnerTest.verify(expectedResults, results);
}
use of org.apache.druid.segment.QueryableIndexSegment in project druid by druid-io.
the class DoubleStorageTest method testMetaDataAnalysis.
@Test
public void testMetaDataAnalysis() {
QueryRunner runner = QueryRunnerTestHelper.makeQueryRunner(METADATA_QR_FACTORY, SEGMENT_ID, new QueryableIndexSegment(index, SEGMENT_ID), null);
SegmentMetadataQuery segmentMetadataQuery = Druids.newSegmentMetadataQueryBuilder().dataSource("testing").intervals(ImmutableList.of(INTERVAL)).toInclude(new ListColumnIncluderator(Arrays.asList(TIME_COLUMN, DIM_NAME, DIM_FLOAT_NAME))).analysisTypes(SegmentMetadataQuery.AnalysisType.CARDINALITY, SegmentMetadataQuery.AnalysisType.SIZE, SegmentMetadataQuery.AnalysisType.INTERVAL, SegmentMetadataQuery.AnalysisType.MINMAX).merge(true).build();
List<SegmentAnalysis> results = runner.run(QueryPlus.wrap(segmentMetadataQuery)).toList();
Assert.assertEquals(Collections.singletonList(expectedSegmentAnalysis), results);
}
Aggregations