@Test public void testDataSourceForMVColumns() throws IOException { for (FieldSpec fieldSpec : _schema.getAllFieldSpecs()) { if (!fieldSpec.isSingleValueField()) { String column = fieldSpec.getName(); DataSource actualDataSource = _mutableSegmentImpl.getDataSource(column); DataSource expectedDataSource = _immutableSegment.getDataSource(column); int actualNumDocs = actualDataSource.getDataSourceMetadata().getNumDocs(); int expectedNumDocs = expectedDataSource.getDataSourceMetadata().getNumDocs(); assertEquals(actualNumDocs, expectedNumDocs); Dictionary actualDictionary = actualDataSource.getDictionary(); Dictionary expectedDictionary = expectedDataSource.getDictionary(); assertEquals(actualDictionary.length(), expectedDictionary.length()); int maxNumValuesPerMVEntry = expectedDataSource.getDataSourceMetadata().getMaxNumValuesPerMVEntry(); int[] actualDictIds = new int[maxNumValuesPerMVEntry]; int[] expectedDictIds = new int[maxNumValuesPerMVEntry]; ForwardIndexReader actualReader = actualDataSource.getForwardIndex(); ForwardIndexReader expectedReader = expectedDataSource.getForwardIndex(); try (ForwardIndexReaderContext actualReaderContext = actualReader.createContext(); ForwardIndexReaderContext expectedReaderContext = expectedReader.createContext()) { for (int docId = 0; docId < expectedNumDocs; docId++) { int actualLength = actualReader.getDictIdMV(docId, actualDictIds, actualReaderContext); int expectedLength = expectedReader.getDictIdMV(docId, expectedDictIds, expectedReaderContext); assertEquals(actualLength, expectedLength); for (int i = 0; i < expectedLength; i++) { assertEquals(actualDictionary.get(actualDictIds[i]), expectedDictionary.get(expectedDictIds[i])); } } } } } }
@Override public DataSource getDataSource(String column) { FieldSpec fieldSpec = _schema.getFieldSpecFor(column); if (fieldSpec == null || fieldSpec.isVirtualColumn()) { if (fieldSpec == null) { fieldSpec = _newlyAddedColumnsFieldMap.get(column); Preconditions.checkNotNull(fieldSpec, "FieldSpec for " + column + " should not be null. " + "Potentially invalid column name specified."); } VirtualColumnContext virtualColumnContext = new VirtualColumnContext(fieldSpec, _numDocsIndexed); VirtualColumnProvider virtualColumnProvider = VirtualColumnProviderFactory.buildProvider(virtualColumnContext); return new ImmutableDataSource(virtualColumnProvider.buildMetadata(virtualColumnContext), virtualColumnProvider.buildColumnIndexContainer(virtualColumnContext)); } else { return _indexContainerMap.get(column).toDataSource(); } }
MutableSegmentImpl implements MutableSegment { @Override public DataSource getDataSource(String column) { FieldSpec fieldSpec = _schema.getFieldSpecFor(column); if (fieldSpec == null || fieldSpec.isVirtualColumn()) { if (fieldSpec == null) { fieldSpec = _newlyAddedColumnsFieldMap.get(column); Preconditions.checkNotNull(fieldSpec, "FieldSpec for " + column + " should not be null. " + "Potentially invalid column name specified."); } VirtualColumnContext virtualColumnContext = new VirtualColumnContext(fieldSpec, _numDocsIndexed); VirtualColumnProvider virtualColumnProvider = VirtualColumnProviderFactory.buildProvider(virtualColumnContext); return new ImmutableDataSource(virtualColumnProvider.buildMetadata(virtualColumnContext), virtualColumnProvider.buildColumnIndexContainer(virtualColumnContext)); } else { return _indexContainerMap.get(column).toDataSource(); } } }
MutableSegmentImpl implements MutableSegment { @Override public DataSource getDataSource(String column) { FieldSpec fieldSpec = _schema.getFieldSpecFor(column); if (fieldSpec == null || fieldSpec.isVirtualColumn()) { if (fieldSpec == null) { fieldSpec = _newlyAddedColumnsFieldMap.get(column); Preconditions.checkNotNull(fieldSpec, "FieldSpec for " + column + " should not be null. " + "Potentially invalid column name specified."); } VirtualColumnContext virtualColumnContext = new VirtualColumnContext(fieldSpec, _numDocsIndexed); VirtualColumnProvider virtualColumnProvider = VirtualColumnProviderFactory.buildProvider(virtualColumnContext); return new ImmutableDataSource(virtualColumnProvider.buildMetadata(virtualColumnContext), virtualColumnProvider.buildColumnIndexContainer(virtualColumnContext)); } else { return _indexContainerMap.get(column).toDataSource(); } } MutableSegmentImpl(RealtimeSegmentConfig config, @Nullable ServerMetrics serverMetrics); }
MutableSegmentImpl implements MutableSegment { @Override public DataSource getDataSource(String column) { FieldSpec fieldSpec = _schema.getFieldSpecFor(column); if (fieldSpec == null || fieldSpec.isVirtualColumn()) { if (fieldSpec == null) { fieldSpec = _newlyAddedColumnsFieldMap.get(column); Preconditions.checkNotNull(fieldSpec, "FieldSpec for " + column + " should not be null. " + "Potentially invalid column name specified."); } VirtualColumnContext virtualColumnContext = new VirtualColumnContext(fieldSpec, _numDocsIndexed); VirtualColumnProvider virtualColumnProvider = VirtualColumnProviderFactory.buildProvider(virtualColumnContext); return new ImmutableDataSource(virtualColumnProvider.buildMetadata(virtualColumnContext), virtualColumnProvider.buildColumnIndexContainer(virtualColumnContext)); } else { return _indexContainerMap.get(column).toDataSource(); } } MutableSegmentImpl(RealtimeSegmentConfig config, @Nullable ServerMetrics serverMetrics); SegmentPartitionConfig getSegmentPartitionConfig(); @Deprecated long getMinTime(); @Deprecated long getMaxTime(); void addExtraColumns(Schema newSchema); @SuppressWarnings("NonAtomicOperationOnVolatileField") @Override boolean index(GenericRow row, @Nullable RowMetadata rowMetadata); @Override int getNumDocsIndexed(); @Override String getSegmentName(); @Override SegmentMetadata getSegmentMetadata(); @Override Set<String> getColumnNames(); @Override Set<String> getPhysicalColumnNames(); @Override DataSource getDataSource(String column); @Override List<StarTreeV2> getStarTrees(); GenericRow getRecord(int docId, GenericRow reuse); @Override void destroy(); int[] getSortedDocIdIterationOrderWithSortedColumn(String column); }
MutableSegmentImpl implements MutableSegment { @Override public DataSource getDataSource(String column) { FieldSpec fieldSpec = _schema.getFieldSpecFor(column); if (fieldSpec == null || fieldSpec.isVirtualColumn()) { if (fieldSpec == null) { fieldSpec = _newlyAddedColumnsFieldMap.get(column); Preconditions.checkNotNull(fieldSpec, "FieldSpec for " + column + " should not be null. " + "Potentially invalid column name specified."); } VirtualColumnContext virtualColumnContext = new VirtualColumnContext(fieldSpec, _numDocsIndexed); VirtualColumnProvider virtualColumnProvider = VirtualColumnProviderFactory.buildProvider(virtualColumnContext); return new ImmutableDataSource(virtualColumnProvider.buildMetadata(virtualColumnContext), virtualColumnProvider.buildColumnIndexContainer(virtualColumnContext)); } else { return _indexContainerMap.get(column).toDataSource(); } } MutableSegmentImpl(RealtimeSegmentConfig config, @Nullable ServerMetrics serverMetrics); SegmentPartitionConfig getSegmentPartitionConfig(); @Deprecated long getMinTime(); @Deprecated long getMaxTime(); void addExtraColumns(Schema newSchema); @SuppressWarnings("NonAtomicOperationOnVolatileField") @Override boolean index(GenericRow row, @Nullable RowMetadata rowMetadata); @Override int getNumDocsIndexed(); @Override String getSegmentName(); @Override SegmentMetadata getSegmentMetadata(); @Override Set<String> getColumnNames(); @Override Set<String> getPhysicalColumnNames(); @Override DataSource getDataSource(String column); @Override List<StarTreeV2> getStarTrees(); GenericRow getRecord(int docId, GenericRow reuse); @Override void destroy(); int[] getSortedDocIdIterationOrderWithSortedColumn(String column);  }