diff --git a/.gitignore b/.gitignore index 26a9bfe..fa52577 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ *.iml +.idea target +release.properties diff --git a/pom.xml b/pom.xml index 879d0a8..be26442 100644 --- a/pom.xml +++ b/pom.xml @@ -1,15 +1,24 @@ - + 4.0.0 com.rapid7.presto presto-query-builder - 0.0.32-SNAPSHOT - + 0.0.33-SNAPSHOT + presto-query-builder - A Java library that will help you create queries for Presto programmatically. This will help you test your code and create dynamic queries. + A Java library that will help you create queries for Presto programmatically. This will help you test + your code and create dynamic queries. + https://github.com/rapid7/presto-query-builder + + com.rapid7.insightvm + insightvm-parent-library-pom + 9.0.24 + + Rapid 7, Inc. http://www.rapid7.com @@ -49,41 +58,18 @@ + + 0.249.1 + + com.facebook.presto presto-parser - 0.240.1 - - - - com.google.guava - guava - 24.1-jre - - - - junit - junit - 4.12 - test + ${presto.parser.version} - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.0 - - 1.8 - 1.8 - - - - - release @@ -98,7 +84,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.7 + 1.7.0 true ossrh @@ -110,13 +96,13 @@ org.apache.maven.plugins maven-source-plugin - 2.2.1 + 3.3.1 - attach-sources - - jar-no-fork - + attach-sources + + jar-no-fork + @@ -124,13 +110,13 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.9.1 + 3.11.1 - attach-javadocs - - jar - + attach-javadocs + + jar + @@ -138,14 +124,14 @@ org.apache.maven.plugins maven-gpg-plugin - 1.5 + 3.2.7 - sign-artifacts - verify - - sign - + sign-artifacts + verify + + sign + @@ -153,7 +139,7 @@ org.apache.maven.plugins maven-release-plugin - 2.5 + 3.1.1 @{project.version} diff --git a/src/main/java/com/rapid7/presto/BasicSelectBuilder.java b/src/main/java/com/rapid7/presto/BasicSelectBuilder.java index 1c5ae65..50fe811 100644 --- a/src/main/java/com/rapid7/presto/BasicSelectBuilder.java +++ b/src/main/java/com/rapid7/presto/BasicSelectBuilder.java @@ -297,8 +297,9 @@ private void completeQuery() { public QueryBody build() { completeQuery(); + Optional optionalFalse = Optional.of(false); if (queries.size() > 1) { - return new Union(queries, false); + return new Union(queries, optionalFalse); } else { return (QueryBody) queries.get(0); } diff --git a/src/test/java/com/rapid7/presto/QueryFactoryTest.java b/src/test/java/com/rapid7/presto/QueryFactoryTest.java index 10cdbe3..d05c678 100644 --- a/src/test/java/com/rapid7/presto/QueryFactoryTest.java +++ b/src/test/java/com/rapid7/presto/QueryFactoryTest.java @@ -5,7 +5,7 @@ // =========================================================================== package com.rapid7.presto; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static com.rapid7.presto.JoinType.INNER; import static com.rapid7.presto.QueryUtils.aliasedTable; import static com.rapid7.presto.QueryUtils.equal; @@ -14,38 +14,46 @@ import static com.rapid7.presto.QueryUtils.projection; import static com.rapid7.presto.QueryUtils.ref; import static com.rapid7.presto.QueryUtils.table; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; -public class QueryFactoryTest { - @Test(expected = UnsupportedOperationException.class) - public void mustSpecifySelect() { +class QueryFactoryTest { + + @Test + void mustSpecifySelect() { // Given QueryFactory qf = new QueryFactory(); - // When - qf.build(new SelectQueryBuilder()); + assertThrows(UnsupportedOperationException.class, () -> { + // When + qf.build(new SelectQueryBuilder()); + }); } - @Test(expected = UnsupportedOperationException.class) - public void mustSpecifySelectWith() { + @Test + void mustSpecifySelectWith() { // Given QueryFactory qf = new QueryFactory(); - // When - qf.build(new SelectQueryBuilder().with("alias").end()); + assertThrows(UnsupportedOperationException.class, () -> { + // When + qf.build(new SelectQueryBuilder().with("alias").end()); + }); } - @Test(expected = UnsupportedOperationException.class) - public void mustSpecifyFrom() { + @Test + void mustSpecifyFrom() { // Given QueryFactory qf = new QueryFactory(); - // When - qf.build(new SelectQueryBuilder().join(INNER, aliasedTable("t1", "b"), equal(ref("a.a"), ref("b.a")))); + assertThrows(UnsupportedOperationException.class, () -> { + // When + qf.build(new SelectQueryBuilder().join(INNER, aliasedTable("t1", "b"), equal(ref("a.a"), ref("b.a")))); + }); } @Test - public void basicSelect() { + void basicSelect() { // Given QueryFactory qf = new QueryFactory(); @@ -57,7 +65,7 @@ public void basicSelect() { } @Test - public void basicJoin() { + void basicJoin() { // Given QueryFactory qf = new QueryFactory(); @@ -76,17 +84,17 @@ public void basicJoin() { // Then assertEquals( "SELECT\n" + - " t1.a t1a\n" + - ", t2.a t2a\n" + - "FROM\n" + - " (a t1\n" + - "INNER JOIN b t2 ON (t1.a = t2.a))", + " t1.a t1a\n" + + ", t2.a t2a\n" + + "FROM\n" + + " (a t1\n" + + "INNER JOIN b t2 ON (t1.a = t2.a))", query ); } @Test - public void basicWith() { + void basicWith() { // Given QueryFactory qf = new QueryFactory(); @@ -111,23 +119,23 @@ public void basicWith() { // Then assertEquals( "WITH\n" + - " with_table AS (\n" + - " SELECT alias.a aliasa\n" + - " FROM\n" + - " b alias\n" + - ") \n" + - "SELECT\n" + - " t1.a t1a\n" + - ", t2.aliasa t2aliasa\n" + - "FROM\n" + - " (a t1\n" + - "INNER JOIN with_table t2 ON (t1.a = t2.aliasa))", + " with_table AS (\n" + + " SELECT alias.a aliasa\n" + + " FROM\n" + + " b alias\n" + + ") \n" + + "SELECT\n" + + " t1.a t1a\n" + + ", t2.aliasa t2aliasa\n" + + "FROM\n" + + " (a t1\n" + + "INNER JOIN with_table t2 ON (t1.a = t2.aliasa))", query ); } @Test - public void multiWith() { + void multiWith() { // Given QueryFactory qf = new QueryFactory(); @@ -158,28 +166,28 @@ public void multiWith() { // Then assertEquals( "WITH\n" + - " with_table_1 AS (\n" + - " SELECT alias1.a alias1a\n" + - " FROM\n" + - " b alias1\n" + - ") \n" + - ", with_table_2 AS (\n" + - " SELECT alias2.a alias2a\n" + - " FROM\n" + - " c alias2\n" + - ") \n" + - "SELECT\n" + - " t1.a t1a\n" + - ", t2.aliasa t2aliasa\n" + - "FROM\n" + - " (a t1\n" + - "INNER JOIN with_table t2 ON (t1.a = t2.aliasa))", + " with_table_1 AS (\n" + + " SELECT alias1.a alias1a\n" + + " FROM\n" + + " b alias1\n" + + ") \n" + + ", with_table_2 AS (\n" + + " SELECT alias2.a alias2a\n" + + " FROM\n" + + " c alias2\n" + + ") \n" + + "SELECT\n" + + " t1.a t1a\n" + + ", t2.aliasa t2aliasa\n" + + "FROM\n" + + " (a t1\n" + + "INNER JOIN with_table t2 ON (t1.a = t2.aliasa))", query ); } @Test - public void basicParameter() { + void basicParameter() { // Given QueryFactory qf = new QueryFactory(); qf.setParam("id", lit("some_id")); @@ -195,15 +203,15 @@ public void basicParameter() { // Then assertEquals( "SELECT t1.a t1a\n" + - "FROM\n" + - " a t1\n" + - "WHERE (t1.id = 'some_id')", + "FROM\n" + + " a t1\n" + + "WHERE (t1.id = 'some_id')", query ); } @Test - public void multiWhere() { + void multiWhere() { // Given QueryFactory qf = new QueryFactory(); qf.setParam("id", lit("some_id")); @@ -222,15 +230,15 @@ public void multiWhere() { // Then assertEquals( "SELECT t1.a t1a\n" + - "FROM\n" + - " a t1\n" + - "WHERE ((((t1.id = 'some_id') AND (t1.name = 'some_name')) AND (t1.title = 'some_title')) OR (t1.id = 'other_id'))", + "FROM\n" + + " a t1\n" + + "WHERE ((((t1.id = 'some_id') AND (t1.name = 'some_name')) AND (t1.title = 'some_title')) OR (t1.id = 'other_id'))", query ); } @Test - public void multiDepthRef() { + void multiDepthRef() { // Given QueryFactory qf = new QueryFactory(); @@ -247,7 +255,7 @@ public void multiDepthRef() { } @Test - public void union() { + void union() { // Given QueryFactory qf = new QueryFactory(); @@ -264,17 +272,17 @@ public void union() { // Then assertEquals( "SELECT t1.a a\n" + - "FROM\n" + - " a t1\n" + - "UNION ALL SELECT t2.a a\n" + - "FROM\n" + - " b t2", + "FROM\n" + + " a t1\n" + + "UNION ALL SELECT t2.a a\n" + + "FROM\n" + + " b t2", query ); } @Test - public void unionWith() { + void unionWith() { // Given QueryFactory qf = new QueryFactory(); @@ -295,45 +303,46 @@ public void unionWith() { // Then assertEquals( "WITH\n" + - " unioned AS (\n" + - " SELECT t1.a a\n" + - " FROM\n" + - " a t1\n" + - "UNION ALL SELECT t2.a a\n" + - " FROM\n" + - " b t2\n" + - ") \n" + - "SELECT u.a a\n" + - "FROM\n" + - " unioned u", + " unioned AS (\n" + + " SELECT t1.a a\n" + + " FROM\n" + + " a t1\n" + + "UNION ALL SELECT t2.a a\n" + + " FROM\n" + + " b t2\n" + + ") \n" + + "SELECT u.a a\n" + + "FROM\n" + + " unioned u", query ); } @Test - public void nullRightForComparison() { + void nullRightForComparison() { equal(ref("someRef"), null); } - @Test(expected = UnsupportedOperationException.class) - public void unsupportedOperationExceptionForComparisonNullRight() { + @Test + void unsupportedOperationExceptionForComparisonNullRight() { // Given QueryFactory qf = new QueryFactory(); - // When - qf.build( - new SelectQueryBuilder( - ).select( - false, - projection("t1", ref("a.a")) - ).from( - table("someTable") - ).where( - equal(ref("someRef"), null) - ) - ); - - // Then - // Throw exception + assertThrows(UnsupportedOperationException.class, () -> { + // When + qf.build( + new SelectQueryBuilder( + ).select( + false, + projection("t1", ref("a.a")) + ).from( + table("someTable") + ).where( + equal(ref("someRef"), null) + ) + ); + // Then + // Throw exception + }); } }