Skip to content

Commit

Permalink
Move TypeSignature to the SPI
Browse files Browse the repository at this point in the history
  • Loading branch information
cberner committed Sep 19, 2014
1 parent 39c44cf commit 5982a90
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 18 deletions.
5 changes: 5 additions & 0 deletions presto-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
</properties>

<dependencies>
<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-spi</artifactId>
</dependency>

<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package com.facebook.presto.client;

import com.facebook.presto.type.TypeSignature;
import com.facebook.presto.spi.type.TypeSignature;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Objects;
Expand All @@ -31,7 +31,7 @@
import java.util.Map;
import java.util.Set;

import static com.facebook.presto.type.TypeSignature.parseTypeSignature;
import static com.facebook.presto.spi.type.TypeSignature.parseTypeSignature;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.unmodifiableIterable;
Expand Down
14 changes: 13 additions & 1 deletion presto-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,19 @@
<shadedPattern>${shadeBase}.client</shadedPattern>
</relocation>
<relocation>
<pattern>com.facebook.presto.type</pattern>
<pattern>com.facebook.presto.spi</pattern>
<shadedPattern>${shadeBase}.type</shadedPattern>
</relocation>
<relocation>
<pattern>com.facebook.presto.spi.block</pattern>
<shadedPattern>${shadeBase}.type</shadedPattern>
</relocation>
<relocation>
<pattern>com.facebook.presto.spi.classloader</pattern>
<shadedPattern>${shadeBase}.type</shadedPattern>
</relocation>
<relocation>
<pattern>com.facebook.presto.spi.type</pattern>
<shadedPattern>${shadeBase}.type</shadedPattern>
</relocation>
<relocation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import java.util.List;

import static com.facebook.presto.type.TypeSignature.parseTypeSignature;
import static com.facebook.presto.spi.type.TypeSignature.parseTypeSignature;
import static com.google.common.base.Preconditions.checkArgument;

public enum OperatorType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import com.facebook.presto.spi.type.Type;
import com.facebook.presto.spi.type.TypeManager;
import com.facebook.presto.type.TypeSignature;
import com.facebook.presto.spi.type.TypeSignature;
import com.facebook.presto.type.UnknownType;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -33,7 +33,7 @@

import static com.facebook.presto.metadata.FunctionRegistry.canCoerce;
import static com.facebook.presto.metadata.FunctionRegistry.mangleOperatorName;
import static com.facebook.presto.type.TypeSignature.parseTypeSignature;
import static com.facebook.presto.spi.type.TypeSignature.parseTypeSignature;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.facebook.presto.spi.type.Type;
import com.facebook.presto.spi.type.TypeManager;
import com.facebook.presto.spi.type.TypeSignature;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.FluentIterable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.type;
package com.facebook.presto.spi.type;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static java.lang.String.format;
import static java.util.Collections.unmodifiableList;

public class TypeSignature
{
Expand All @@ -36,10 +32,12 @@ public class TypeSignature

private TypeSignature(String base, List<TypeSignature> parameters)
{
this.base = checkNotNull(base, "base is null");
checkArgument(base != null, "base is null");
this.base = base;
checkArgument(!base.isEmpty(), "base is empty");
checkArgument(!Pattern.matches(".*[<>,].*", base), "Bad characters in base type: %s", base);
this.parameters = ImmutableList.copyOf(checkNotNull(parameters, "parameters is null"));
checkArgument(parameters != null, "parameters is null");
this.parameters = unmodifiableList(new ArrayList<>(parameters));
}

@Override
Expand All @@ -48,7 +46,16 @@ public String toString()
{
String typeName = base;
if (!parameters.isEmpty()) {
typeName += "<" + Joiner.on(",").join(parameters) + ">";
typeName += "<";
boolean first = true;
for (TypeSignature parameter : parameters) {
if (!first) {
typeName += ",";
}
first = false;
typeName += parameter.toString();
}
typeName += ">";
}

return typeName;
Expand All @@ -70,7 +77,7 @@ public List<TypeSignature> getParameters()
public static TypeSignature parseTypeSignature(String signature)
{
if (!signature.contains("<")) {
return new TypeSignature(signature, ImmutableList.<TypeSignature>of());
return new TypeSignature(signature, unmodifiableList(new ArrayList<TypeSignature>()));
}

String baseName = null;
Expand Down Expand Up @@ -132,4 +139,18 @@ public int hashCode()
{
return Objects.hash(base, parameters);
}

private static void checkArgument(boolean argument, String format, Object...args)
{
if (!argument) {
throw new IllegalArgumentException(format(format, args));
}
}

private static void checkState(boolean argument, String format, Object...args)
{
if (!argument) {
throw new IllegalStateException(format(format, args));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.type;
package com.facebook.presto.spi.type;

import com.google.common.base.Function;
import com.google.common.base.Joiner;
Expand All @@ -21,7 +21,7 @@

import java.util.List;

import static com.facebook.presto.type.TypeSignature.parseTypeSignature;
import static com.facebook.presto.spi.type.TypeSignature.parseTypeSignature;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;

Expand Down

0 comments on commit 5982a90

Please sign in to comment.