github-code-scanning[bot] commented on code in PR #14048:
URL: https://github.com/apache/druid/pull/14048#discussion_r1160863661
##########
extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQSelectTest.java:
##########
@@ -508,6 +510,87 @@
}
+ @Test
+ public void testSelectLookup()
+ {
+ final RowSignature rowSignature = RowSignature.builder().add("EXPR$0",
ColumnType.LONG).build();
+
+ testSelectQuery()
+ .setSql("select count(*) from lookup.lookyloo")
+ .setQueryContext(context)
+ .setExpectedMSQSpec(
+ MSQSpec.builder()
+ .query(
+ GroupByQuery.builder()
+ .setDataSource(new
LookupDataSource("lookyloo"))
+
.setInterval(querySegmentSpec(Filtration.eternity()))
+ .setGranularity(Granularities.ALL)
+ .setAggregatorSpecs(aggregators(new
CountAggregatorFactory("a0")))
+ .setContext(context)
+ .build())
+ .columnMappings(new ColumnMappings(ImmutableList.of(new
ColumnMapping("a0", "EXPR$0"))))
+ .tuningConfig(MSQTuningConfig.defaultConfig())
+ .build())
+ .setExpectedRowSignature(rowSignature)
+ .setExpectedResultRows(ImmutableList.of(new Object[]{4L}))
+ .verifyResults();
+ }
+
+ @Test
+ public void testJoinWithLookup()
+ {
+ final RowSignature rowSignature =
+ RowSignature.builder()
+ .add("v", ColumnType.STRING)
+ .add("cnt", ColumnType.LONG)
+ .build();
+
+ testSelectQuery()
+ .setSql("SELECT lookyloo.v, COUNT(*) AS cnt\n"
+ + "FROM foo LEFT JOIN lookup.lookyloo ON foo.dim2 =
lookyloo.k\n"
+ + "WHERE lookyloo.v <> 'xa'\n"
+ + "GROUP BY lookyloo.v")
+ .setQueryContext(context)
+ .setExpectedMSQSpec(
+ MSQSpec.builder()
+ .query(
+ GroupByQuery.builder()
+ .setDataSource(
+ join(
+ new
TableDataSource(CalciteTests.DATASOURCE1),
+ new LookupDataSource("lookyloo"),
+ "j0.",
+
equalsCondition(makeColumnExpression("dim2"), makeColumnExpression("j0.k")),
Review Comment:
## Deprecated method or constructor invocation
Invoking [CalciteTestBase.makeColumnExpression](1) should be avoided because
it has been deprecated.
[Show more
details](https://github.com/apache/druid/security/code-scanning/4738)
##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/input/lookup/LookupInputSliceReader.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.druid.msq.input.lookup;
+
+import com.google.common.collect.Iterators;
+import org.apache.druid.java.util.common.ISE;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.java.util.common.Pair;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.msq.counters.CounterTracker;
+import org.apache.druid.msq.input.InputSlice;
+import org.apache.druid.msq.input.InputSliceReader;
+import org.apache.druid.msq.input.ReadableInput;
+import org.apache.druid.msq.input.ReadableInputs;
+import org.apache.druid.msq.input.table.SegmentWithDescriptor;
+import org.apache.druid.msq.querykit.LazyResourceHolder;
+import org.apache.druid.query.LookupDataSource;
+import org.apache.druid.segment.Segment;
+import org.apache.druid.segment.SegmentWrangler;
+import org.apache.druid.timeline.SegmentId;
+import org.apache.druid.utils.CloseableUtils;
+
+import java.util.Iterator;
+import java.util.function.Consumer;
+
+/**
+ * Reads {@link LookupInputSlice} using a {@link SegmentWrangler} (which is
expected to contain a
+ * {@link org.apache.druid.segment.LookupSegmentWrangler}).
+ */
+public class LookupInputSliceReader implements InputSliceReader
+{
+ private static final Logger log = new Logger(LookupInputSliceReader.class);
+
+ private final SegmentWrangler segmentWrangler;
+
+ public LookupInputSliceReader(SegmentWrangler segmentWrangler)
+ {
+ this.segmentWrangler = segmentWrangler;
+ }
+
+ @Override
+ public int numReadableInputs(InputSlice slice)
+ {
+ return 1;
+ }
+
+ @Override
+ public ReadableInputs attach(
+ final int inputNumber,
+ final InputSlice slice,
+ final CounterTracker counters,
+ final Consumer<Throwable> warningPublisher
+ )
+ {
+ final String lookupName = ((LookupInputSlice) slice).getLookupName();
+
+ return ReadableInputs.segments(
+ () -> Iterators.singletonIterator(
+ ReadableInput.segment(
+ new SegmentWithDescriptor(
+ new LazyResourceHolder<>(
+ () -> {
+ final Iterable<Segment> segments =
+ segmentWrangler.getSegmentsForIntervals(
+ new LookupDataSource(lookupName),
+ Intervals.ONLY_ETERNITY
+ );
+
+ final Iterator<Segment> segmentIterator =
segments.iterator();
+ if (!segmentIterator.hasNext()) {
+ throw new ISE("Lookup[%s] is not loaded");
Review Comment:
## Missing format argument
This format call refers to 1 argument(s) but only supplies 0 argument(s).
[Show more
details](https://github.com/apache/druid/security/code-scanning/4739)
##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/input/lookup/LookupInputSliceReader.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.druid.msq.input.lookup;
+
+import com.google.common.collect.Iterators;
+import org.apache.druid.java.util.common.ISE;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.java.util.common.Pair;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.msq.counters.CounterTracker;
+import org.apache.druid.msq.input.InputSlice;
+import org.apache.druid.msq.input.InputSliceReader;
+import org.apache.druid.msq.input.ReadableInput;
+import org.apache.druid.msq.input.ReadableInputs;
+import org.apache.druid.msq.input.table.SegmentWithDescriptor;
+import org.apache.druid.msq.querykit.LazyResourceHolder;
+import org.apache.druid.query.LookupDataSource;
+import org.apache.druid.segment.Segment;
+import org.apache.druid.segment.SegmentWrangler;
+import org.apache.druid.timeline.SegmentId;
+import org.apache.druid.utils.CloseableUtils;
+
+import java.util.Iterator;
+import java.util.function.Consumer;
+
+/**
+ * Reads {@link LookupInputSlice} using a {@link SegmentWrangler} (which is
expected to contain a
+ * {@link org.apache.druid.segment.LookupSegmentWrangler}).
+ */
+public class LookupInputSliceReader implements InputSliceReader
+{
+ private static final Logger log = new Logger(LookupInputSliceReader.class);
+
+ private final SegmentWrangler segmentWrangler;
+
+ public LookupInputSliceReader(SegmentWrangler segmentWrangler)
+ {
+ this.segmentWrangler = segmentWrangler;
+ }
+
+ @Override
+ public int numReadableInputs(InputSlice slice)
+ {
+ return 1;
+ }
+
+ @Override
+ public ReadableInputs attach(
+ final int inputNumber,
+ final InputSlice slice,
+ final CounterTracker counters,
+ final Consumer<Throwable> warningPublisher
+ )
+ {
+ final String lookupName = ((LookupInputSlice) slice).getLookupName();
+
+ return ReadableInputs.segments(
+ () -> Iterators.singletonIterator(
+ ReadableInput.segment(
+ new SegmentWithDescriptor(
+ new LazyResourceHolder<>(
+ () -> {
+ final Iterable<Segment> segments =
+ segmentWrangler.getSegmentsForIntervals(
+ new LookupDataSource(lookupName),
+ Intervals.ONLY_ETERNITY
+ );
+
+ final Iterator<Segment> segmentIterator =
segments.iterator();
+ if (!segmentIterator.hasNext()) {
+ throw new ISE("Lookup[%s] is not loaded");
+ }
+
+ final Segment segment = segmentIterator.next();
+ if (segmentIterator.hasNext()) {
+ // LookupSegmentWrangler always returns zero or
one segments, so this code block can't
+ // happen. That being said: we'll program
defensively anyway.
+ CloseableUtils.closeAndSuppressExceptions(
+ segment,
+ e -> log.warn(e, "Failed to close segment for
lookup[%s]", lookupName)
+ );
+ throw new ISE("Lookup[%s] has multiple segments;
cannot read");
Review Comment:
## Missing format argument
This format call refers to 1 argument(s) but only supplies 0 argument(s).
[Show more
details](https://github.com/apache/druid/security/code-scanning/4740)
##########
extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQSelectTest.java:
##########
@@ -508,6 +510,87 @@
}
+ @Test
+ public void testSelectLookup()
+ {
+ final RowSignature rowSignature = RowSignature.builder().add("EXPR$0",
ColumnType.LONG).build();
+
+ testSelectQuery()
+ .setSql("select count(*) from lookup.lookyloo")
+ .setQueryContext(context)
+ .setExpectedMSQSpec(
+ MSQSpec.builder()
+ .query(
+ GroupByQuery.builder()
+ .setDataSource(new
LookupDataSource("lookyloo"))
+
.setInterval(querySegmentSpec(Filtration.eternity()))
+ .setGranularity(Granularities.ALL)
+ .setAggregatorSpecs(aggregators(new
CountAggregatorFactory("a0")))
+ .setContext(context)
+ .build())
+ .columnMappings(new ColumnMappings(ImmutableList.of(new
ColumnMapping("a0", "EXPR$0"))))
+ .tuningConfig(MSQTuningConfig.defaultConfig())
+ .build())
+ .setExpectedRowSignature(rowSignature)
+ .setExpectedResultRows(ImmutableList.of(new Object[]{4L}))
+ .verifyResults();
+ }
+
+ @Test
+ public void testJoinWithLookup()
+ {
+ final RowSignature rowSignature =
+ RowSignature.builder()
+ .add("v", ColumnType.STRING)
+ .add("cnt", ColumnType.LONG)
+ .build();
+
+ testSelectQuery()
+ .setSql("SELECT lookyloo.v, COUNT(*) AS cnt\n"
+ + "FROM foo LEFT JOIN lookup.lookyloo ON foo.dim2 =
lookyloo.k\n"
+ + "WHERE lookyloo.v <> 'xa'\n"
+ + "GROUP BY lookyloo.v")
+ .setQueryContext(context)
+ .setExpectedMSQSpec(
+ MSQSpec.builder()
+ .query(
+ GroupByQuery.builder()
+ .setDataSource(
+ join(
+ new
TableDataSource(CalciteTests.DATASOURCE1),
+ new LookupDataSource("lookyloo"),
+ "j0.",
+
equalsCondition(makeColumnExpression("dim2"), makeColumnExpression("j0.k")),
Review Comment:
## Deprecated method or constructor invocation
Invoking [CalciteTestBase.makeColumnExpression](1) should be avoided because
it has been deprecated.
[Show more
details](https://github.com/apache/druid/security/code-scanning/4737)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]