Skip to content

Commit 603bb67

Browse files
committed
refactor: split out PhysicalSegmentColumnInspector from PhysicalSegmentInspector
1 parent 80d7700 commit 603bb67

12 files changed

Lines changed: 78 additions & 35 deletions

File tree

benchmarks/src/test/java/org/apache/druid/benchmark/query/SqlBaseBenchmark.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import org.apache.druid.segment.AutoTypeColumnSchema;
6666
import org.apache.druid.segment.IncrementalIndexSegment;
6767
import org.apache.druid.segment.IndexSpec;
68+
import org.apache.druid.segment.PhysicalSegmentColumnInspector;
6869
import org.apache.druid.segment.PhysicalSegmentInspector;
6970
import org.apache.druid.segment.QueryableIndex;
7071
import org.apache.druid.segment.QueryableIndexCursorFactory;
@@ -521,7 +522,7 @@ public SegmentId getId()
521522
public <T> T as(@Nonnull Class<T> clazz)
522523
{
523524
// computed sql schema uses segment metadata, which relies on physical inspector, use the underlying index
524-
if (clazz.equals(PhysicalSegmentInspector.class)) {
525+
if (clazz.equals(PhysicalSegmentInspector.class) || clazz.equals(PhysicalSegmentColumnInspector.class)) {
525526
return (T) new QueryableIndexPhysicalSegmentInspector(index);
526527
}
527528
return super.as(clazz);
@@ -548,7 +549,7 @@ public SegmentId getId()
548549
public <T> T as(@Nonnull Class<T> clazz)
549550
{
550551
// computed sql schema uses segment metadata, which relies on physical inspector, use the underlying index
551-
if (clazz.equals(PhysicalSegmentInspector.class)) {
552+
if (clazz.equals(PhysicalSegmentInspector.class) || clazz.equals(PhysicalSegmentColumnInspector.class)) {
552553
return (T) new QueryableIndexPhysicalSegmentInspector(index);
553554
}
554555
return super.as(clazz);

multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestBase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
import org.apache.druid.segment.CursorFactory;
146146
import org.apache.druid.segment.IndexBuilder;
147147
import org.apache.druid.segment.IndexIO;
148+
import org.apache.druid.segment.PhysicalSegmentColumnInspector;
148149
import org.apache.druid.segment.PhysicalSegmentInspector;
149150
import org.apache.druid.segment.QueryableIndex;
150151
import org.apache.druid.segment.QueryableIndexCursorFactory;
@@ -791,7 +792,7 @@ public <T> T as(@Nonnull Class<T> clazz)
791792
{
792793
if (CursorFactory.class.equals(clazz)) {
793794
return (T) new QueryableIndexCursorFactory(index);
794-
} else if (PhysicalSegmentInspector.class.equals(clazz)) {
795+
} else if (PhysicalSegmentInspector.class.equals(clazz) || PhysicalSegmentColumnInspector.class.equals(clazz)) {
795796
return (T) new QueryableIndexPhysicalSegmentInspector(index);
796797
} else if (QueryableIndex.class.equals(clazz)) {
797798
return (T) index;

processing/src/main/java/org/apache/druid/query/metadata/SegmentAnalyzer.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.druid.segment.CursorFactory;
3232
import org.apache.druid.segment.CursorHolder;
3333
import org.apache.druid.segment.DimensionSelector;
34+
import org.apache.druid.segment.PhysicalSegmentColumnInspector;
3435
import org.apache.druid.segment.PhysicalSegmentInspector;
3536
import org.apache.druid.segment.QueryableIndex;
3637
import org.apache.druid.segment.Segment;
@@ -90,8 +91,9 @@ public Map<String, ColumnAnalysis> analyze(Segment segment)
9091
{
9192
Preconditions.checkNotNull(segment, "segment");
9293
final PhysicalSegmentInspector segmentInspector = segment.as(PhysicalSegmentInspector.class);
94+
final PhysicalSegmentColumnInspector columnInspector = segment.as(PhysicalSegmentColumnInspector.class);
9395

94-
// index is null for incremental-index-based segments, but segmentInspector should always be available
96+
// index is null for incremental-index-based segments, but the inspectors should always be available
9597
final QueryableIndex index = segment.as(QueryableIndex.class);
9698
final CursorFactory cursorFactory = Objects.requireNonNull(segment.as(CursorFactory.class));
9799

@@ -104,8 +106,8 @@ public Map<String, ColumnAnalysis> analyze(Segment segment)
104106
for (String columnName : rowSignature.getColumnNames()) {
105107
final ColumnCapabilities capabilities;
106108

107-
if (segmentInspector != null) {
108-
capabilities = segmentInspector.getColumnCapabilities(columnName);
109+
if (columnInspector != null) {
110+
capabilities = columnInspector.getColumnCapabilities(columnName);
109111
} else {
110112
capabilities = null;
111113
}
@@ -135,7 +137,7 @@ public Map<String, ColumnAnalysis> analyze(Segment segment)
135137
if (index != null) {
136138
analysis = analyzeStringColumn(capabilities, index.getColumnHolder(columnName));
137139
} else {
138-
analysis = analyzeStringColumn(capabilities, segmentInspector, cursorFactory, columnName);
140+
analysis = analyzeStringColumn(capabilities, columnInspector, cursorFactory, columnName);
139141
}
140142
break;
141143
case ARRAY:
@@ -260,7 +262,7 @@ private ColumnAnalysis analyzeStringColumn(
260262

261263
private ColumnAnalysis analyzeStringColumn(
262264
final ColumnCapabilities capabilities,
263-
@Nullable final PhysicalSegmentInspector analysisInspector,
265+
@Nullable final PhysicalSegmentColumnInspector analysisInspector,
264266
final CursorFactory cursorFactory,
265267
final String columnName
266268
)

processing/src/main/java/org/apache/druid/segment/IncrementalIndexSegment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public <T> T as(final Class<T> clazz)
6464
return (T) new IncrementalIndexMaxIngestedEventTimeInspector(index);
6565
} else if (Metadata.class.equals(clazz)) {
6666
return (T) index.getMetadata();
67-
} else if (PhysicalSegmentInspector.class.equals(clazz)) {
67+
} else if (PhysicalSegmentInspector.class.equals(clazz) || PhysicalSegmentColumnInspector.class.equals(clazz)) {
6868
return (T) new IncrementalIndexPhysicalSegmentInspector(index);
6969
} else if (TopNOptimizationInspector.class.equals(clazz)) {
7070
return (T) new SimpleTopNOptimizationInspector(true);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.druid.segment;
21+
22+
import javax.annotation.Nullable;
23+
24+
/**
25+
* Interface for methods describing the columns of physical segments such as {@link QueryableIndexSegment} and
26+
* {@link IncrementalIndexSegment} that is not typically used at query time (outside of metadata queries).
27+
* <p>
28+
* For general metadata information about a segment that is not column specific, use {@link PhysicalSegmentInspector}
29+
* instead.
30+
*/
31+
public interface PhysicalSegmentColumnInspector extends ColumnInspector
32+
{
33+
/**
34+
* Returns the minimum value of the provided column, if known through an index, dictionary, or cache. Returns null
35+
* if not known. Does not scan the column to find the minimum value.
36+
*/
37+
@Nullable
38+
Comparable getMinValue(String column);
39+
40+
/**
41+
* Returns the minimum value of the provided column, if known through an index, dictionary, or cache. Returns null
42+
* if not known. Does not scan the column to find the maximum value.
43+
*/
44+
@Nullable
45+
Comparable getMaxValue(String column);
46+
47+
/**
48+
* Returns the number of distinct values in a column, if known, or
49+
* {@link DimensionDictionarySelector#CARDINALITY_UNKNOWN} if not.
50+
*/
51+
int getDimensionCardinality(String column);
52+
}

processing/src/main/java/org/apache/druid/segment/PhysicalSegmentInspector.java

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,16 @@
2424
/**
2525
* Interface for methods describing physical segments such as {@link QueryableIndexSegment} and
2626
* {@link IncrementalIndexSegment} that is not typically used at query time (outside of metadata queries).
27+
* <p>
28+
* For metadata information about specific columns, use {@link PhysicalSegmentColumnInspector}.
2729
*/
28-
public interface PhysicalSegmentInspector extends ColumnInspector
30+
public interface PhysicalSegmentInspector
2931
{
3032
/**
3133
* Returns {@link Metadata} which contains details about how the segment was created
3234
*/
3335
@Nullable
3436
Metadata getMetadata();
35-
/**
36-
* Returns the minimum value of the provided column, if known through an index, dictionary, or cache. Returns null
37-
* if not known. Does not scan the column to find the minimum value.
38-
*/
39-
@Nullable
40-
Comparable getMinValue(String column);
41-
42-
/**
43-
* Returns the minimum value of the provided column, if known through an index, dictionary, or cache. Returns null
44-
* if not known. Does not scan the column to find the maximum value.
45-
*/
46-
@Nullable
47-
Comparable getMaxValue(String column);
48-
49-
/**
50-
* Returns the number of distinct values in a column, if known, or
51-
* {@link DimensionDictionarySelector#CARDINALITY_UNKNOWN} if not.}
52-
*/
53-
int getDimensionCardinality(String column);
5437

5538
/**
5639
* Returns the number of rows in the segment

processing/src/main/java/org/apache/druid/segment/QueryableIndexPhysicalSegmentInspector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import java.io.IOException;
3131
import java.io.UncheckedIOException;
3232

33-
public class QueryableIndexPhysicalSegmentInspector implements PhysicalSegmentInspector
33+
public class QueryableIndexPhysicalSegmentInspector implements PhysicalSegmentInspector, PhysicalSegmentColumnInspector
3434
{
3535
private final QueryableIndex index;
3636

processing/src/main/java/org/apache/druid/segment/QueryableIndexSegment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public <T> T as(@Nonnull Class<T> clazz)
9191
return (T) timeBoundaryInspector;
9292
} else if (Metadata.class.equals(clazz)) {
9393
return (T) index.getMetadata();
94-
} else if (PhysicalSegmentInspector.class.equals(clazz)) {
94+
} else if (PhysicalSegmentInspector.class.equals(clazz) || PhysicalSegmentColumnInspector.class.equals(clazz)) {
9595
return (T) new QueryableIndexPhysicalSegmentInspector(index);
9696
} else if (TopNOptimizationInspector.class.equals(clazz)) {
9797
return (T) new SimpleTopNOptimizationInspector(true);

processing/src/main/java/org/apache/druid/segment/Segment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public interface Segment extends Closeable
6868
* <li> {@link IndexedTable}, table object, if this is a joinable indexed table.
6969
* <li> {@link TimeBoundaryInspector}, inspector for min/max timestamps, if supported by this segment.
7070
* <li> {@link PhysicalSegmentInspector}, inspector for physical segment details, if supported by this segment.
71+
* <li> {@link PhysicalSegmentColumnInspector}, inspector for physical segment column details, if supported by this segment.
7172
* <li> {@link MaxIngestedEventTimeInspector}, inspector for {@link DataSourceMetadataResultValue#getMaxIngestedEventTime()}
7273
* <li> {@link TopNOptimizationInspector}, inspector containing information for topN specific optimizations
7374
* <li> {@link CloseableShapeshifter}, stepping stone to {@link org.apache.druid.query.rowsandcols.RowsAndColumns}.

processing/src/main/java/org/apache/druid/segment/incremental/IncrementalIndexPhysicalSegmentInspector.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@
2222
import org.apache.druid.segment.DimensionDictionarySelector;
2323
import org.apache.druid.segment.DimensionIndexer;
2424
import org.apache.druid.segment.Metadata;
25+
import org.apache.druid.segment.PhysicalSegmentColumnInspector;
2526
import org.apache.druid.segment.PhysicalSegmentInspector;
2627
import org.apache.druid.segment.column.ColumnCapabilities;
2728
import org.apache.druid.segment.column.ColumnCapabilitiesImpl;
2829
import org.apache.druid.segment.column.ColumnHolder;
2930

3031
import javax.annotation.Nullable;
3132

32-
public class IncrementalIndexPhysicalSegmentInspector implements PhysicalSegmentInspector
33+
public class IncrementalIndexPhysicalSegmentInspector
34+
implements PhysicalSegmentInspector, PhysicalSegmentColumnInspector
3335
{
3436
static final ColumnCapabilities.CoercionLogic SNAPSHOT_COERCE_LOGIC =
3537
new ColumnCapabilities.CoercionLogic()

0 commit comments

Comments
 (0)