Skip to content

Commit

Permalink
Support guessing BinData type as varbinary in MongoDB
Browse files Browse the repository at this point in the history
This supports BinData type in DBRef field.
  • Loading branch information
ebyhr committed Feb 23, 2022
1 parent cd6ed66 commit d72b25e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import io.trino.spi.type.TypeSignatureParameter;
import io.trino.spi.type.VarcharType;
import org.bson.Document;
import org.bson.types.Binary;
import org.bson.types.ObjectId;

import java.util.ArrayList;
Expand Down Expand Up @@ -80,6 +81,7 @@
import static io.trino.spi.type.SmallintType.SMALLINT;
import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS;
import static io.trino.spi.type.TinyintType.TINYINT;
import static io.trino.spi.type.VarbinaryType.VARBINARY;
import static io.trino.spi.type.VarcharType.VARCHAR;
import static io.trino.spi.type.VarcharType.createUnboundedVarcharType;
import static java.lang.Math.toIntExact;
Expand Down Expand Up @@ -600,6 +602,9 @@ private Optional<TypeSignature> guessFieldType(Object value)
if (value instanceof String) {
typeSignature = createUnboundedVarcharType().getTypeSignature();
}
if (value instanceof Binary) {
typeSignature = VARBINARY.getTypeSignature();
}
else if (value instanceof Integer || value instanceof Long) {
typeSignature = BIGINT.getTypeSignature();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ public Object[][] dbRefProvider()
{
return new Object[][] {
{"String type", "varchar 'String type'", "varchar"},
{"BinData".getBytes(UTF_8), "to_utf8('BinData')", "varbinary"},
{1234567890, "bigint '1234567890'", "bigint"},
{true, "true", "boolean"},
{12.3f, "double '12.3'", "double"},
Expand Down

0 comments on commit d72b25e

Please sign in to comment.