From b3048241342a58900ef0e1a16aa08e263d1d20cf Mon Sep 17 00:00:00 2001 From: Andrew Pilloud Date: Mon, 21 May 2018 16:19:41 -0700 Subject: [PATCH] [SQL] Build mega jar for JDBC --- LICENSE | 105 +++++++++++++++++- sdks/java/extensions/sql/jdbc/build.gradle | 42 +++++++ .../sdk/extensions/sql/jdbc/BeamSqlLine.java | 35 ++++++ .../sdk/extensions/sql/jdbc/package-info.java | 20 ++++ .../extensions/sql/jdbc/BeamSqlLineTest.java | 55 +++++++++ settings.gradle | 2 + 6 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 sdks/java/extensions/sql/jdbc/build.gradle create mode 100644 sdks/java/extensions/sql/jdbc/src/main/java/org/apache/beam/sdk/extensions/sql/jdbc/BeamSqlLine.java create mode 100644 sdks/java/extensions/sql/jdbc/src/main/java/org/apache/beam/sdk/extensions/sql/jdbc/package-info.java create mode 100644 sdks/java/extensions/sql/jdbc/src/test/java/org/apache/beam/sdk/extensions/sql/jdbc/BeamSqlLineTest.java diff --git a/LICENSE b/LICENSE index 4dda9e3e5ddf..a2e93e2819c0 100644 --- a/LICENSE +++ b/LICENSE @@ -298,4 +298,107 @@ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + jline: + Copyright (c) 2002-2016, the original author or authors. + All rights reserved. + + http://www.opensource.org/licenses/bsd-license.php + + Redistribution and use in source and binary forms, with or + without modification, are permitted provided that the following + conditions are met: + + Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with + the distribution. + + Neither the name of JLine nor the names of its contributors + may be used to endorse or promote products derived from this + software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, + BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + OF THE POSSIBILITY OF SUCH DAMAGE. + + sqlline: + SQLLine - Shell for issuing SQL to relational databases via JDBC + + Copyright (c) 2002,2003,2004,2005,2006,2007 Marc Prud'hommeaux + Copyright (c) 2004-2010 The Eigenbase Project + Copyright (c) 2013-2017 Julian Hyde + All rights reserved. + + =============================================================================== + + Licensed under the Modified BSD License (the "License"); you may not + use this file except in compliance with the License. You may obtain a + copy of the License at: + + http://opensource.org/licenses/BSD-3-Clause + + Redistribution and use in source and binary forms, + with or without modification, are permitted provided + that the following conditions are met: + + (1) Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + (2) Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the + distribution. + + (3) The name of the author may not be used to endorse or promote + products derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + slf4j: + Copyright (c) 2004-2017 QOS.ch + All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE diff --git a/sdks/java/extensions/sql/jdbc/build.gradle b/sdks/java/extensions/sql/jdbc/build.gradle new file mode 100644 index 000000000000..4fba3bd1ccc7 --- /dev/null +++ b/sdks/java/extensions/sql/jdbc/build.gradle @@ -0,0 +1,42 @@ +/* + * 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. + */ + +apply from: project(":").file("build_rules.gradle") +applyJavaNature(failOnWarning: true, enableSpotless: true, testShadowJar: true, shadowClosure: {}) + +dependencies { + compile project(path: ":beam-sdks-java-extensions-sql", configuration: "shadow") + compile "jline:jline:2.14.6" + compile "sqlline:sqlline:1.3.0" + compile library.java.slf4j_jdk14 + compileOnly library.java.findbugs_annotations + testCompileOnly library.java.findbugs_annotations +} + +shadowJar { + manifest { + attributes "Main-Class": "org.apache.beam.sdk.extensions.sql.jdbc.BeamSqlLine" + } +} + +test { + doFirst { + // Assert everything is in the output or test jar + assert classpath.size() == 2 + } +} diff --git a/sdks/java/extensions/sql/jdbc/src/main/java/org/apache/beam/sdk/extensions/sql/jdbc/BeamSqlLine.java b/sdks/java/extensions/sql/jdbc/src/main/java/org/apache/beam/sdk/extensions/sql/jdbc/BeamSqlLine.java new file mode 100644 index 000000000000..7952b0620c34 --- /dev/null +++ b/sdks/java/extensions/sql/jdbc/src/main/java/org/apache/beam/sdk/extensions/sql/jdbc/BeamSqlLine.java @@ -0,0 +1,35 @@ +/* + * 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.beam.sdk.extensions.sql.jdbc; + +import static org.apache.beam.sdk.extensions.sql.impl.JdbcDriver.CONNECT_STRING_PREFIX; + +import java.io.IOException; +import sqlline.SqlLine; + +/** {@link BeamSqlLine} provides default arguments to SqlLine. */ +public class BeamSqlLine { + public static void main(String[] args) throws IOException { + String[] args2 = new String[2 + args.length]; + args2[0] = "-u"; + args2[1] = CONNECT_STRING_PREFIX; + System.arraycopy(args, 0, args2, 2, args.length); + + SqlLine.main(args2); + } +} diff --git a/sdks/java/extensions/sql/jdbc/src/main/java/org/apache/beam/sdk/extensions/sql/jdbc/package-info.java b/sdks/java/extensions/sql/jdbc/src/main/java/org/apache/beam/sdk/extensions/sql/jdbc/package-info.java new file mode 100644 index 000000000000..ae3eaff16afd --- /dev/null +++ b/sdks/java/extensions/sql/jdbc/src/main/java/org/apache/beam/sdk/extensions/sql/jdbc/package-info.java @@ -0,0 +1,20 @@ +/* + * 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. + */ + +/** Provides default commandline for sqlline. */ +package org.apache.beam.sdk.extensions.sql.jdbc; diff --git a/sdks/java/extensions/sql/jdbc/src/test/java/org/apache/beam/sdk/extensions/sql/jdbc/BeamSqlLineTest.java b/sdks/java/extensions/sql/jdbc/src/test/java/org/apache/beam/sdk/extensions/sql/jdbc/BeamSqlLineTest.java new file mode 100644 index 000000000000..cee3aa7142dd --- /dev/null +++ b/sdks/java/extensions/sql/jdbc/src/test/java/org/apache/beam/sdk/extensions/sql/jdbc/BeamSqlLineTest.java @@ -0,0 +1,55 @@ +/* + * 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.beam.sdk.extensions.sql.jdbc; + +import org.junit.Test; + +/** + * Test for {@link org.apache.beam.sdk.extensions.sql.jdbc.BeamSqlLine}. Note that this test only + * tests for crashes (due to ClassNotFoundException for example). It does not test output. + */ +public class BeamSqlLineTest { + + @Test + public void testSqlLine_emptyArgs() throws Exception { + BeamSqlLine.main(new String[] {}); + } + + @Test + public void testSqlLine_nullCommand() throws Exception { + BeamSqlLine.main(new String[] {"-e", ""}); + } + + @Test + public void testSqlLine_simple() throws Exception { + BeamSqlLine.main(new String[] {"-e", "SELECT 1;"}); + } + + @Test + public void testSqlLine_parse() throws Exception { + BeamSqlLine.main(new String[] {"-e", "SELECT 'beam';"}); + } + + @Test + public void testSqlLine_ddl() throws Exception { + BeamSqlLine.main( + new String[] { + "-e", "CREATE TABLE test (id INTEGER) TYPE 'text';", "-e", "DROP TABLE test;" + }); + } +} diff --git a/settings.gradle b/settings.gradle index 670a513fbfb8..0b89a609a33e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -84,6 +84,8 @@ include "beam-sdks-java-extensions-sorter" project(":beam-sdks-java-extensions-sorter").dir = file("sdks/java/extensions/sorter") include "beam-sdks-java-extensions-sql" project(":beam-sdks-java-extensions-sql").dir = file("sdks/java/extensions/sql") +include "beam-sdks-java-extensions-sql-jdbc" +project(":beam-sdks-java-extensions-sql-jdbc").dir = file("sdks/java/extensions/sql/jdbc") include "beam-sdks-java-fn-execution" project(":beam-sdks-java-fn-execution").dir = file("sdks/java/fn-execution") include "beam-sdks-java-harness"