Skip to content

Commit

Permalink
Add AbstarctTestNativeTpchConnector
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe-Abraham committed Jul 15, 2024
1 parent 2599027 commit b67de20
Show file tree
Hide file tree
Showing 19 changed files with 202 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ public class ContainerQueryRunner
private static final String PRESTO_WORKER_IMAGE = System.getProperty("workerImage", "presto-worker:latest");
private static final String BASE_DIR = System.getProperty("user.dir");
private final GenericContainer<?> coordinator;
private final GenericContainer<?> worker;
private final GenericContainer<?> worker1;
private final GenericContainer<?> worker2;
private final GenericContainer<?> worker3;
private final GenericContainer<?> worker4;

public ContainerQueryRunner()
{
Expand All @@ -72,15 +75,39 @@ public ContainerQueryRunner()
.waitingFor(Wait.forLogMessage(".*======== SERVER STARTED ========.*", 1))
.withStartupTimeout(Duration.ofSeconds(120));

worker = new GenericContainer<>(PRESTO_WORKER_IMAGE)
worker1 = new GenericContainer<>(PRESTO_WORKER_IMAGE)
.withExposedPorts(7777)
.withNetwork(network).withNetworkAliases("presto-worker")
.withFileSystemBind(BASE_DIR + "/testcontainers/nativeworker/velox-etc", "/opt/presto-server/etc", BindMode.READ_ONLY)
.withFileSystemBind(BASE_DIR + "/testcontainers/nativeworker/entrypoint.sh", "/opt/entrypoint.sh", BindMode.READ_ONLY)
.waitingFor(Wait.forLogMessage(".*Announcement succeeded: HTTP 202.*", 1));

worker2 = new GenericContainer<>(PRESTO_WORKER_IMAGE)
.withExposedPorts(7778)
.withNetwork(network).withNetworkAliases("presto-worker")
.withFileSystemBind(BASE_DIR + "/testcontainers/nativeworker2/velox-etc", "/opt/presto-server/etc", BindMode.READ_ONLY)
.withFileSystemBind(BASE_DIR + "/testcontainers/nativeworker2/entrypoint.sh", "/opt/entrypoint.sh", BindMode.READ_ONLY)
.waitingFor(Wait.forLogMessage(".*Announcement succeeded: HTTP 202.*", 1));

worker3 = new GenericContainer<>(PRESTO_WORKER_IMAGE)
.withExposedPorts(7779)
.withNetwork(network).withNetworkAliases("presto-worker")
.withFileSystemBind(BASE_DIR + "/testcontainers/nativeworker3/velox-etc", "/opt/presto-server/etc", BindMode.READ_ONLY)
.withFileSystemBind(BASE_DIR + "/testcontainers/nativeworker3/entrypoint.sh", "/opt/entrypoint.sh", BindMode.READ_ONLY)
.waitingFor(Wait.forLogMessage(".*Announcement succeeded: HTTP 202.*", 1));

worker4 = new GenericContainer<>(PRESTO_WORKER_IMAGE)
.withExposedPorts(7780)
.withNetwork(network).withNetworkAliases("presto-worker")
.withFileSystemBind(BASE_DIR + "/testcontainers/nativeworker4/velox-etc", "/opt/presto-server/etc", BindMode.READ_ONLY)
.withFileSystemBind(BASE_DIR + "/testcontainers/nativeworker4/entrypoint.sh", "/opt/entrypoint.sh", BindMode.READ_ONLY)
.waitingFor(Wait.forLogMessage(".*Announcement succeeded: HTTP 202.*", 1));

coordinator.start();
worker.start();
worker1.start();
worker2.start();
worker3.start();
worker4.start();

System.out.println("Presto UI is accessible at http://localhost:" + coordinator.getMappedPort(8081));

Expand All @@ -92,6 +119,7 @@ public ContainerQueryRunner()
}
}


public static MaterializedResult toMaterializedResult(String csvData)
{
List<MaterializedRow> rows = new ArrayList<>();
Expand Down Expand Up @@ -241,10 +269,10 @@ public Container.ExecResult executeQuery(String sql)
execResult = coordinator.execInContainer(command);
}
catch (IOException e) {
throw new RuntimeException(e);
fail("Presto CLI failed with error message: " + e.getMessage());
}
catch (InterruptedException e) {
throw new RuntimeException(e);
fail("Presto CLI failed with error message: " + e.getMessage());
}

if (execResult.getExitCode() != 0) {
Expand All @@ -257,8 +285,17 @@ public Container.ExecResult executeQuery(String sql)
@Override
public void close()
{
try {
TimeUnit.SECONDS.sleep(2000);
}
catch (InterruptedException e) {
throw new RuntimeException(e);
}
coordinator.stop();
worker.stop();
worker1.stop();
worker2.stop();
worker3.stop();
worker4.stop();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed 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 com.facebook.presto.nativeworker;

import com.facebook.presto.testing.QueryRunner;
import com.facebook.presto.tests.AbstractTestNativeTpchConnector;

public class TestPrestoContainerTpchConnector
extends AbstractTestNativeTpchConnector
{
@Override
protected QueryRunner createQueryRunner()
throws Exception
{
return new ContainerQueryRunner();
}
}
16 changes: 16 additions & 0 deletions presto-native-execution/testcontainers/nativeworker2/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh
# Licensed 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.

GLOG_logtostderr=1 presto_server \
--etc-dir=/opt/presto-server/etc

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
connector.name=hive
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connector.name=tpch
tpch.column-naming=STANDARD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
presto.version=testversion
http-server.http.port=7778
discovery.uri=http://presto-coordinator:8081
system-memory-gb=2
native.sidecar=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node.environment=testing
node.id=native-worker-2
node.location=testing-location
16 changes: 16 additions & 0 deletions presto-native-execution/testcontainers/nativeworker3/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh
# Licensed 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.

GLOG_logtostderr=1 presto_server \
--etc-dir=/opt/presto-server/etc

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
connector.name=hive
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connector.name=tpch
tpch.column-naming=STANDARD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
presto.version=testversion
http-server.http.port=7779
discovery.uri=http://presto-coordinator:8081
system-memory-gb=2
native.sidecar=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node.environment=testing
node.id=native-worker-3
node.location=testing-location
16 changes: 16 additions & 0 deletions presto-native-execution/testcontainers/nativeworker4/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh
# Licensed 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.

GLOG_logtostderr=1 presto_server \
--etc-dir=/opt/presto-server/etc

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
connector.name=hive
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connector.name=tpch
tpch.column-naming=STANDARD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
presto.version=testversion
http-server.http.port=7780
discovery.uri=http://presto-coordinator:8081
system-memory-gb=2
native.sidecar=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node.environment=testing
node.id=native-worker-4
node.location=testing-location
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Licensed 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 com.facebook.presto.tests;

import org.testng.annotations.Test;

public abstract class AbstractTestNativeTpchConnector
extends AbstractTestQueryFramework
{
@Test
public void testTpchTinyTables()
{
assertQuery("SELECT count(*) FROM customer");
assertQuery("SELECT count(*) FROM lineitem");
assertQuery("SELECT count(*) FROM orders");
assertQuery("SELECT count(*) FROM nation");
assertQuery("SELECT count(*) FROM part");
assertQuery("SELECT count(*) FROM partsupp");
assertQuery("SELECT count(*) FROM region");
assertQuery("SELECT count(*) FROM supplier");
assertQuery("SELECT c_custkey, c_name, c_nationkey FROM customer",
"SELECT custkey, name, nationkey FROM customer");
assertQuery("SELECT n_nationkey, n_name, n_regionkey FROM nation",
"SELECT nationkey, name, regionkey FROM nation");
assertQuery("SELECT r_regionkey, r_name FROM region",
"SELECT regionkey, name FROM region");
assertQuery("SELECT SUM(l_discount) FROM lineitem WHERE l_discount != 0.04",
"SELECT SUM(discount) FROM lineitem WHERE discount != 0.04");
assertQuery("SELECT ps_partkey, ps_availqty, ps_supplycost FROM partsupp WHERE ps_availqty < 5",
"SELECT partkey, availqty, supplycost FROM partsupp WHERE availqty < 5");
assertQuery("SELECT p_partkey, p_mfgr, p_brand FROM part WHERE p_size = 4 and p_partkey < 1000",
"SELECT partkey, mfgr, brand FROM part WHERE size = 4 and partkey < 1000");
assertQuery("SELECT s_suppkey, s_phone FROM supplier WHERE s_acctbal < 100",
"SELECT suppkey, phone FROM supplier WHERE acctbal < 100");
assertQuery("SELECT c_custkey, c_phone FROM customer WHERE c_acctbal > 9900",
"SELECT custkey, phone FROM customer WHERE acctbal > 9900");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6197,7 +6197,7 @@ public void testMultipleOrderingOnSameCanonicalVariables()
}

@Test
public void tesMultipleConcat()
public void testMultipleConcat()
{
assertQuery("select concat('a', '','','', 'b', '', '', 'c', 'd', '', '', '', '')", "select 'abcd'");
assertQuery("select concat('', '','','', '', '', '', '', '', '', '')", "select ''");
Expand Down

0 comments on commit b67de20

Please sign in to comment.