mattcasters commented on code in PR #8574:
URL: https://github.com/apache/hop/pull/8574#discussion_r4093027999
##########
plugins/transforms/joinrows/src/main/java/org/apache/hop/pipeline/transforms/joinrows/JoinRowsMeta.java:
##########
@@ -52,7 +52,8 @@
description = "i18n::BaseTransform.TypeTooltipDesc.JoinRows",
categoryDescription =
"i18n:org.apache.hop.pipeline.transform:BaseTransform.Category.Joins",
keywords = "i18n::JoinRowsMeta.keyword",
- documentationUrl = "/pipeline/transforms/joinrows.html")
+ documentationUrl = "/pipeline/transforms/joinrows.html",
+ excludedEngines = {"Beam*", "SparkPipelineEngine"})
Review Comment:
**[bug]** `excludedEngines = {"Beam*", "SparkPipelineEngine"}` is enforced
only by `EngineCompatibilityResolver` inside `Pipeline.prepareExecution` (and
the palette filter). That gate is skipped when `HOP_ALLOW_UNSUPPORTED` is set
(`--allow-unsupported` or the GUI "Run anyway" button): it logs and continues.
The paths that still execute the transform do not know about this exclusion.
`HopPipelineMetaToBeamPipelineConverter.HARD_BANNED_META_TYPES` /
`validateTransformBeamUsage` and
`HopPipelineMetaToSparkConverter.HARD_BANNED_PLUGIN_IDS` /
`validateTransformSparkUsage` are what `BeamPipelineEngine.supports` and
`SparkPipelineEngine.supports` read, and what throw while the pipeline graph is
built. Group By, Sort Rows, Unique Rows, and Unique Rows (HashSet) are on those
maps; Join Rows is not, even though this PR adds it to the Beam "unsupported
transforms" list that the manual says those engines refuse with an error. After
the override, Beam's generic handler still runs the transfor
m (`pipeline` type `SingleThreaded`, main input as an info side view, other
inputs one element at a time, or flattened into one `PCollection`).
`batchComplete()` is gone and `readRow` treats an empty row set as
end-of-stream, so the old infinite loop is gone, but the run succeeds with a
partial product (the rows one worker happens to hold) instead of failing.
Native Spark's generic `mapPartitions` path does the same per partition.
**Suggestion:** Add `JoinRowsMeta` to `HARD_BANNED_META_TYPES` and plugin id
`JoinRows` to `HARD_BANNED_PLUGIN_IDS`, with a reason that points at the
constant-field + Merge Join workaround. Extend
`HopPipelineMetaToSparkConverterTest.hardBannedTransformsExcludeNativeSparkOnAnnotation`
(`bannedMetas`) in the same change; that test fails if the Spark ban list and
the annotation drift. Keep the `excludedEngines` annotation so the palette and
the default `hop-run`/GUI gate still refuse the transform before a graph is
built.
##########
plugins/transforms/joinrows/src/test/java/org/apache/hop/pipeline/transforms/joinrows/JoinRowsSingleThreadedTest.java:
##########
@@ -0,0 +1,211 @@
+/*
+ * 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.hop.pipeline.transforms.joinrows;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.hop.core.HopEnvironment;
+import org.apache.hop.core.RowMetaAndData;
+import org.apache.hop.core.annotations.Transform;
+import org.apache.hop.core.plugins.PluginRegistry;
+import org.apache.hop.core.plugins.TransformPluginType;
+import org.apache.hop.core.row.IRowMeta;
+import org.apache.hop.core.row.RowMeta;
+import org.apache.hop.core.row.value.ValueMetaInteger;
+import org.apache.hop.core.row.value.ValueMetaString;
+import org.apache.hop.pipeline.Pipeline;
+import org.apache.hop.pipeline.PipelineHopMeta;
+import org.apache.hop.pipeline.PipelineMeta;
+import org.apache.hop.pipeline.RowProducer;
+import org.apache.hop.pipeline.SingleThreadedPipelineExecutor;
+import org.apache.hop.pipeline.engines.local.LocalPipelineEngine;
+import org.apache.hop.pipeline.transform.ITransform;
+import org.apache.hop.pipeline.transform.ITransformMeta;
+import org.apache.hop.pipeline.transform.TransformMeta;
+import org.apache.hop.pipeline.transforms.dummy.DummyMeta;
+import org.apache.hop.pipeline.transforms.injector.InjectorMeta;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Runs Join Rows through the {@link SingleThreadedPipelineExecutor}: the
executor behind the single
+ * threaded pipeline engine and single threaded sub-pipelines (#2353).
+ *
+ * <p>The executor calls processRow() once per row waiting on the input row
sets, and for as long as
+ * the main stream (an info stream of Join Rows) holds rows. The rows on the
input row sets are the
+ * complete input, but the row sets are not flagged as done, so any read
beyond them would wait
+ * forever.
+ */
+class JoinRowsSingleThreadedTest {
+
+ private static final Duration TIMEOUT = Duration.ofSeconds(20);
+
+ @BeforeAll
+ static void initHop() throws Exception {
+ HopEnvironment.init();
+ PluginRegistry registry = PluginRegistry.getInstance();
+ for (ITransformMeta meta : List.of(new JoinRowsMeta(), new InjectorMeta(),
new DummyMeta())) {
+ if (registry.getPluginId(TransformPluginType.class, meta) == null) {
+ registry.registerPluginClass(
+ meta.getClass().getName(), TransformPluginType.class,
Transform.class);
+ }
+ }
+ }
+
+ @Test
+ void cartesianProductOfTwoInputs() throws Exception {
+ List<RowMetaAndData> rows = assertTimeoutPreemptively(TIMEOUT, () ->
runJoin(3, 2, 500, false));
+
+ assertEquals(6, rows.size());
+ assertProduct(rows, 3, 2);
+ }
+
+ @Test
+ void cartesianProductWhenInputRowSetsAreFinished() throws Exception {
+ List<RowMetaAndData> rows = assertTimeoutPreemptively(TIMEOUT, () ->
runJoin(3, 2, 500, true));
+
+ assertEquals(6, rows.size());
+ assertProduct(rows, 3, 2);
+ }
+
+ @Test
+ void cartesianProductSpillingToTemporaryFile() throws Exception {
+ // A cache size below the number of rows makes the transform read the rows
back from disk.
+ List<RowMetaAndData> rows = assertTimeoutPreemptively(TIMEOUT, () ->
runJoin(4, 5, 2, false));
+
+ assertEquals(20, rows.size());
+ assertProduct(rows, 4, 5);
+ }
+
+ @Test
+ void noOutputWhenOneInputIsEmpty() throws Exception {
+ List<RowMetaAndData> rows = assertTimeoutPreemptively(TIMEOUT, () ->
runJoin(3, 0, 500, false));
+
+ assertTrue(rows.isEmpty());
+ }
+
+ @Test
+ void singleInputPassesRowsThrough() throws Exception {
+ // This is how the Beam engine used to feed the transform: all inputs
flattened into one row
+ // set, one row per iteration. The old batchComplete() hung on the row
that was left behind.
+ List<RowMetaAndData> rows =
+ assertTimeoutPreemptively(TIMEOUT, () -> runJoin(3, -1, 500, false));
+
+ assertEquals(3, rows.size());
+ }
+
+ private static void assertProduct(List<RowMetaAndData> rows, int nrMain, int
nrOther)
+ throws Exception {
+ List<String> expected = new ArrayList<>();
+ for (long id = 1; id <= nrMain; id++) {
+ for (int n = 1; n <= nrOther; n++) {
+ expected.add(id + "-name" + n);
+ }
+ }
+ List<String> actual = new ArrayList<>();
+ for (RowMetaAndData row : rows) {
+ assertEquals(2, row.getRowMeta().size());
+ actual.add(row.getInteger("id") + "-" + row.getString("name", null));
+ }
+ assertEquals(expected, actual);
+ }
+
+ private static List<RowMetaAndData> runJoin(
+ int nrMain, int nrOther, int cacheSize, boolean finishInputs) throws
Exception {
+ PipelineMeta pipelineMeta = new PipelineMeta();
+ pipelineMeta.setName("join-rows-single-threaded");
+
+ TransformMeta main = addTransform(pipelineMeta, "main", new
InjectorMeta());
+ // A negative number of rows leaves the second input out of the pipeline
+ TransformMeta other =
+ nrOther < 0 ? null : addTransform(pipelineMeta, "other", new
InjectorMeta());
+
+ JoinRowsMeta joinRowsMeta = new JoinRowsMeta();
+ joinRowsMeta.setDefault();
+ joinRowsMeta.setCacheSize(cacheSize);
+ joinRowsMeta.setMainTransformName("main");
Review Comment:
**[suggestion]** Every new test attaches the main stream as the first hop:
the unit test adds injector `"main"` before `"other"`, and the integration
pipelines hop `ids` / `pass ids` into Join Rows before the other inputs
(`0003-join-rows-three-inputs.hpl` sets `<main>ids</main>` on the first of
three hops). `initialize()` only makes a non-first main stream into file 0 via
`swapFirstInputRowSetIfExists`, and the new `do/while (data.filenr != 0)` loop
assumes file 0 is that stream. Nothing in this PR fails if that swap is skipped
or applied to the wrong row set. The three-input case is only in the
integration project (which `integration-tests/scripts/run-tests.sh` will pick
up: no `disabled.txt`, and the daily loop runs every project directory), not in
the unit test that actually drives `SingleThreadedPipelineExecutor`.
**Suggestion:** Add one unit-test case with three inputs whose main
transform is not the first hop, and assert the full product with main fields
first. The same layout in one of the `single_threaded` pipelines would lock it
in the integration run as well.
--
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]