From d1e1448cfbfc4f54f5c64a3ad2a01d409909aede Mon Sep 17 00:00:00 2001 From: Martin Traverso Date: Mon, 15 Oct 2012 20:08:06 -0700 Subject: [PATCH] Add preconditions --- .../java/com/facebook/presto/sql/tree/AliasedRelation.java | 4 ++++ .../com/facebook/presto/sql/tree/BetweenPredicate.java | 5 +++++ .../com/facebook/presto/sql/tree/CoalesceExpression.java | 3 +++ .../com/facebook/presto/sql/tree/ComparisonExpression.java | 5 +++++ .../java/com/facebook/presto/sql/tree/DateLiteral.java | 2 ++ .../java/com/facebook/presto/sql/tree/DoubleLiteral.java | 2 ++ .../java/com/facebook/presto/sql/tree/ExistsPredicate.java | 2 ++ .../java/com/facebook/presto/sql/tree/IntervalLiteral.java | 4 ++++ .../com/facebook/presto/sql/tree/IsNotNullPredicate.java | 2 ++ .../java/com/facebook/presto/sql/tree/IsNullPredicate.java | 2 ++ src/main/java/com/facebook/presto/sql/tree/Join.java | 4 ++++ .../java/com/facebook/presto/sql/tree/LikePredicate.java | 4 ++++ .../facebook/presto/sql/tree/LogicalBinaryExpression.java | 5 +++++ .../java/com/facebook/presto/sql/tree/LongLiteral.java | 2 ++ .../java/com/facebook/presto/sql/tree/NotExpression.java | 2 ++ src/main/java/com/facebook/presto/sql/tree/Query.java | 7 +++++++ .../facebook/presto/sql/tree/SearchedCaseExpression.java | 2 ++ .../com/facebook/presto/sql/tree/SimpleCaseExpression.java | 4 ++++ .../java/com/facebook/presto/sql/tree/StringLiteral.java | 2 ++ .../java/com/facebook/presto/sql/tree/TimeLiteral.java | 2 ++ .../com/facebook/presto/sql/tree/TimestampLiteral.java | 3 +++ 21 files changed, 68 insertions(+) diff --git a/src/main/java/com/facebook/presto/sql/tree/AliasedRelation.java b/src/main/java/com/facebook/presto/sql/tree/AliasedRelation.java index abe7a46ee515..6e7b885231b0 100644 --- a/src/main/java/com/facebook/presto/sql/tree/AliasedRelation.java +++ b/src/main/java/com/facebook/presto/sql/tree/AliasedRelation.java @@ -1,6 +1,7 @@ package com.facebook.presto.sql.tree; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; import java.util.List; @@ -13,6 +14,9 @@ public class AliasedRelation public AliasedRelation(Relation relation, String alias, List columnNames) { + Preconditions.checkNotNull(relation, "relation is null"); + Preconditions.checkNotNull(alias, " is null"); + this.relation = relation; this.alias = alias; this.columnNames = columnNames; diff --git a/src/main/java/com/facebook/presto/sql/tree/BetweenPredicate.java b/src/main/java/com/facebook/presto/sql/tree/BetweenPredicate.java index 0f3452d82dc8..b260c12f5ada 100644 --- a/src/main/java/com/facebook/presto/sql/tree/BetweenPredicate.java +++ b/src/main/java/com/facebook/presto/sql/tree/BetweenPredicate.java @@ -1,6 +1,7 @@ package com.facebook.presto.sql.tree; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; public class BetweenPredicate extends Expression @@ -11,6 +12,10 @@ public class BetweenPredicate public BetweenPredicate(Expression value, Expression min, Expression max) { + Preconditions.checkNotNull(value, "value is null"); + Preconditions.checkNotNull(min, "min is null"); + Preconditions.checkNotNull(max, "max is null"); + this.value = value; this.min = min; this.max = max; diff --git a/src/main/java/com/facebook/presto/sql/tree/CoalesceExpression.java b/src/main/java/com/facebook/presto/sql/tree/CoalesceExpression.java index deefd3e3c5e1..d87b2ac9b175 100644 --- a/src/main/java/com/facebook/presto/sql/tree/CoalesceExpression.java +++ b/src/main/java/com/facebook/presto/sql/tree/CoalesceExpression.java @@ -1,6 +1,7 @@ package com.facebook.presto.sql.tree; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import java.util.List; @@ -12,6 +13,8 @@ public class CoalesceExpression public CoalesceExpression(List operands) { + Preconditions.checkNotNull(operands, "operands is null"); + this.operands = ImmutableList.copyOf(operands); } diff --git a/src/main/java/com/facebook/presto/sql/tree/ComparisonExpression.java b/src/main/java/com/facebook/presto/sql/tree/ComparisonExpression.java index 36c1e7c5d4aa..8890263e04d6 100644 --- a/src/main/java/com/facebook/presto/sql/tree/ComparisonExpression.java +++ b/src/main/java/com/facebook/presto/sql/tree/ComparisonExpression.java @@ -1,6 +1,7 @@ package com.facebook.presto.sql.tree; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; public class ComparisonExpression extends Expression @@ -32,6 +33,10 @@ public String getValue() public ComparisonExpression(Type type, Expression left, Expression right) { + Preconditions.checkNotNull(type, "type is null"); + Preconditions.checkNotNull(left, "left is null"); + Preconditions.checkNotNull(right, "right is null"); + this.type = type; this.left = left; this.right = right; diff --git a/src/main/java/com/facebook/presto/sql/tree/DateLiteral.java b/src/main/java/com/facebook/presto/sql/tree/DateLiteral.java index 45539f049e26..8edbe7bab47a 100644 --- a/src/main/java/com/facebook/presto/sql/tree/DateLiteral.java +++ b/src/main/java/com/facebook/presto/sql/tree/DateLiteral.java @@ -1,6 +1,7 @@ package com.facebook.presto.sql.tree; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; public class DateLiteral extends Literal @@ -9,6 +10,7 @@ public class DateLiteral public DateLiteral(String value) { + Preconditions.checkNotNull(value, "value is null"); this.value = value; } diff --git a/src/main/java/com/facebook/presto/sql/tree/DoubleLiteral.java b/src/main/java/com/facebook/presto/sql/tree/DoubleLiteral.java index 3e7b5ec306bb..d9230d5b01f4 100644 --- a/src/main/java/com/facebook/presto/sql/tree/DoubleLiteral.java +++ b/src/main/java/com/facebook/presto/sql/tree/DoubleLiteral.java @@ -1,6 +1,7 @@ package com.facebook.presto.sql.tree; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; public class DoubleLiteral extends Literal @@ -9,6 +10,7 @@ public class DoubleLiteral public DoubleLiteral(String value) { + Preconditions.checkNotNull(value, "value is null"); this.value = value; } diff --git a/src/main/java/com/facebook/presto/sql/tree/ExistsPredicate.java b/src/main/java/com/facebook/presto/sql/tree/ExistsPredicate.java index 1e1d197f5abb..a67dd54d39a9 100644 --- a/src/main/java/com/facebook/presto/sql/tree/ExistsPredicate.java +++ b/src/main/java/com/facebook/presto/sql/tree/ExistsPredicate.java @@ -1,6 +1,7 @@ package com.facebook.presto.sql.tree; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; public class ExistsPredicate extends Expression @@ -9,6 +10,7 @@ public class ExistsPredicate public ExistsPredicate(Query subquery) { + Preconditions.checkNotNull(subquery, "subquery is null"); this.subquery = subquery; } diff --git a/src/main/java/com/facebook/presto/sql/tree/IntervalLiteral.java b/src/main/java/com/facebook/presto/sql/tree/IntervalLiteral.java index 41dab8fba66c..c0a96895dee7 100644 --- a/src/main/java/com/facebook/presto/sql/tree/IntervalLiteral.java +++ b/src/main/java/com/facebook/presto/sql/tree/IntervalLiteral.java @@ -1,6 +1,7 @@ package com.facebook.presto.sql.tree; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; public class IntervalLiteral extends Literal @@ -16,6 +17,9 @@ public enum Sign public IntervalLiteral(String value, String type, Sign sign) { + Preconditions.checkNotNull(value, "value is null"); + Preconditions.checkNotNull(type, "type is null"); + this.value = value; this.type = type; this.sign = sign; diff --git a/src/main/java/com/facebook/presto/sql/tree/IsNotNullPredicate.java b/src/main/java/com/facebook/presto/sql/tree/IsNotNullPredicate.java index 4055fab5f25b..3a8f338de341 100644 --- a/src/main/java/com/facebook/presto/sql/tree/IsNotNullPredicate.java +++ b/src/main/java/com/facebook/presto/sql/tree/IsNotNullPredicate.java @@ -1,6 +1,7 @@ package com.facebook.presto.sql.tree; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; public class IsNotNullPredicate extends Expression @@ -9,6 +10,7 @@ public class IsNotNullPredicate public IsNotNullPredicate(Expression value) { + Preconditions.checkNotNull(value, "value is null"); this.value = value; } diff --git a/src/main/java/com/facebook/presto/sql/tree/IsNullPredicate.java b/src/main/java/com/facebook/presto/sql/tree/IsNullPredicate.java index c63f58add3fb..978746e43797 100644 --- a/src/main/java/com/facebook/presto/sql/tree/IsNullPredicate.java +++ b/src/main/java/com/facebook/presto/sql/tree/IsNullPredicate.java @@ -1,6 +1,7 @@ package com.facebook.presto.sql.tree; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; public class IsNullPredicate extends Expression @@ -9,6 +10,7 @@ public class IsNullPredicate public IsNullPredicate(Expression value) { + Preconditions.checkNotNull(value, "value is null"); this.value = value; } diff --git a/src/main/java/com/facebook/presto/sql/tree/Join.java b/src/main/java/com/facebook/presto/sql/tree/Join.java index 9eb97ef46e7f..410f431c53a2 100644 --- a/src/main/java/com/facebook/presto/sql/tree/Join.java +++ b/src/main/java/com/facebook/presto/sql/tree/Join.java @@ -1,12 +1,16 @@ package com.facebook.presto.sql.tree; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; public class Join extends Relation { public Join(Type type, Relation left, Relation right, JoinCriteria criteria) { + Preconditions.checkNotNull(left, "left is null"); + Preconditions.checkNotNull(right, "right is null"); + this.type = type; this.left = left; this.right = right; diff --git a/src/main/java/com/facebook/presto/sql/tree/LikePredicate.java b/src/main/java/com/facebook/presto/sql/tree/LikePredicate.java index 64f35c544253..75e6282409eb 100644 --- a/src/main/java/com/facebook/presto/sql/tree/LikePredicate.java +++ b/src/main/java/com/facebook/presto/sql/tree/LikePredicate.java @@ -1,6 +1,7 @@ package com.facebook.presto.sql.tree; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; public class LikePredicate extends Expression @@ -10,6 +11,9 @@ public class LikePredicate private final Expression escape; public LikePredicate(Expression value, Expression pattern, Expression escape) { + Preconditions.checkNotNull(value, "value is null"); + Preconditions.checkNotNull(pattern, "pattern is null"); + this.value = value; this.pattern = pattern; this.escape = escape; diff --git a/src/main/java/com/facebook/presto/sql/tree/LogicalBinaryExpression.java b/src/main/java/com/facebook/presto/sql/tree/LogicalBinaryExpression.java index a16d22010448..77b6ae329b37 100644 --- a/src/main/java/com/facebook/presto/sql/tree/LogicalBinaryExpression.java +++ b/src/main/java/com/facebook/presto/sql/tree/LogicalBinaryExpression.java @@ -1,6 +1,7 @@ package com.facebook.presto.sql.tree; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; public class LogicalBinaryExpression extends Expression @@ -16,6 +17,10 @@ public enum Type public LogicalBinaryExpression(Type type, Expression left, Expression right) { + Preconditions.checkNotNull(type, "type is null"); + Preconditions.checkNotNull(left, "left is null"); + Preconditions.checkNotNull(right, "right is null"); + this.type = type; this.left = left; this.right = right; diff --git a/src/main/java/com/facebook/presto/sql/tree/LongLiteral.java b/src/main/java/com/facebook/presto/sql/tree/LongLiteral.java index 94047f5834af..4ff809a4863b 100644 --- a/src/main/java/com/facebook/presto/sql/tree/LongLiteral.java +++ b/src/main/java/com/facebook/presto/sql/tree/LongLiteral.java @@ -1,6 +1,7 @@ package com.facebook.presto.sql.tree; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; public class LongLiteral extends Literal @@ -9,6 +10,7 @@ public class LongLiteral public LongLiteral(String value) { + Preconditions.checkNotNull(value, "value is null"); this.value = value; } diff --git a/src/main/java/com/facebook/presto/sql/tree/NotExpression.java b/src/main/java/com/facebook/presto/sql/tree/NotExpression.java index 0a329bc55f28..743b6c051447 100644 --- a/src/main/java/com/facebook/presto/sql/tree/NotExpression.java +++ b/src/main/java/com/facebook/presto/sql/tree/NotExpression.java @@ -1,6 +1,7 @@ package com.facebook.presto.sql.tree; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; public class NotExpression extends Expression @@ -9,6 +10,7 @@ public class NotExpression public NotExpression(Expression value) { + Preconditions.checkNotNull(value, "value is null"); this.value = value; } diff --git a/src/main/java/com/facebook/presto/sql/tree/Query.java b/src/main/java/com/facebook/presto/sql/tree/Query.java index 4d8689cdf0de..2a6887990ded 100644 --- a/src/main/java/com/facebook/presto/sql/tree/Query.java +++ b/src/main/java/com/facebook/presto/sql/tree/Query.java @@ -1,6 +1,7 @@ package com.facebook.presto.sql.tree; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; import java.util.List; @@ -24,6 +25,12 @@ public Query( List orderBy, String limit) { + Preconditions.checkNotNull(select, "select is null"); + Preconditions.checkNotNull(from, "from is null"); + Preconditions.checkArgument(!from.isEmpty(), "from is empty"); + Preconditions.checkNotNull(groupBy, "groupBy is null"); + Preconditions.checkNotNull(orderBy, "orderBy is null"); + this.select = select; this.from = from; this.where = where; diff --git a/src/main/java/com/facebook/presto/sql/tree/SearchedCaseExpression.java b/src/main/java/com/facebook/presto/sql/tree/SearchedCaseExpression.java index 203f59881a46..ef6fcfefeaeb 100644 --- a/src/main/java/com/facebook/presto/sql/tree/SearchedCaseExpression.java +++ b/src/main/java/com/facebook/presto/sql/tree/SearchedCaseExpression.java @@ -1,6 +1,7 @@ package com.facebook.presto.sql.tree; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import java.util.List; @@ -13,6 +14,7 @@ public class SearchedCaseExpression public SearchedCaseExpression(List whenClauses, Expression defaultValue) { + Preconditions.checkNotNull(whenClauses, "whenClauses is null"); this.whenClauses = ImmutableList.copyOf(whenClauses); this.defaultValue = defaultValue; } diff --git a/src/main/java/com/facebook/presto/sql/tree/SimpleCaseExpression.java b/src/main/java/com/facebook/presto/sql/tree/SimpleCaseExpression.java index 35972f5eba35..4ec91ce32383 100644 --- a/src/main/java/com/facebook/presto/sql/tree/SimpleCaseExpression.java +++ b/src/main/java/com/facebook/presto/sql/tree/SimpleCaseExpression.java @@ -1,6 +1,7 @@ package com.facebook.presto.sql.tree; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import java.util.List; @@ -14,6 +15,9 @@ public class SimpleCaseExpression public SimpleCaseExpression(Expression operand, List whenClauses, Expression defaultValue) { + Preconditions.checkNotNull(operand, "operand is null"); + Preconditions.checkNotNull(whenClauses, "whenClauses is null"); + this.operand = operand; this.whenClauses = ImmutableList.copyOf(whenClauses); this.defaultValue = defaultValue; diff --git a/src/main/java/com/facebook/presto/sql/tree/StringLiteral.java b/src/main/java/com/facebook/presto/sql/tree/StringLiteral.java index a62d39fbb21d..5c1c9c5d1a5e 100644 --- a/src/main/java/com/facebook/presto/sql/tree/StringLiteral.java +++ b/src/main/java/com/facebook/presto/sql/tree/StringLiteral.java @@ -1,6 +1,7 @@ package com.facebook.presto.sql.tree; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; public class StringLiteral extends Literal @@ -9,6 +10,7 @@ public class StringLiteral public StringLiteral(String value) { + Preconditions.checkNotNull(value, "value is null"); this.value = value; } diff --git a/src/main/java/com/facebook/presto/sql/tree/TimeLiteral.java b/src/main/java/com/facebook/presto/sql/tree/TimeLiteral.java index d8c8768eceb0..d487c2860947 100644 --- a/src/main/java/com/facebook/presto/sql/tree/TimeLiteral.java +++ b/src/main/java/com/facebook/presto/sql/tree/TimeLiteral.java @@ -1,6 +1,7 @@ package com.facebook.presto.sql.tree; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; public class TimeLiteral extends Literal @@ -9,6 +10,7 @@ public class TimeLiteral public TimeLiteral(String value) { + Preconditions.checkNotNull(value, "value is null"); this.value = value; } diff --git a/src/main/java/com/facebook/presto/sql/tree/TimestampLiteral.java b/src/main/java/com/facebook/presto/sql/tree/TimestampLiteral.java index 8a88c6c736e5..5e9da0502f94 100644 --- a/src/main/java/com/facebook/presto/sql/tree/TimestampLiteral.java +++ b/src/main/java/com/facebook/presto/sql/tree/TimestampLiteral.java @@ -1,6 +1,7 @@ package com.facebook.presto.sql.tree; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; public class TimestampLiteral extends Literal @@ -9,6 +10,8 @@ public class TimestampLiteral public TimestampLiteral(String value) { + Preconditions.checkNotNull(value, "value is null"); + this.value = value; }