Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public LiteralContext(DataType type, @Nullable Object value) {
_pinotDataType = getPinotDataType(type, value);
}

// TODO: Revisit MV support for BOOLEAN, BIG_DECIMAL, BYTES and UUID.
@Nullable
private static PinotDataType getPinotDataType(DataType type, @Nullable Object value) {
if (value == null) {
Expand Down Expand Up @@ -174,6 +175,9 @@ private static PinotDataType getPinotDataType(DataType type, @Nullable Object va
return PinotDataType.BIG_DECIMAL;
case STRING:
return singleValue ? PinotDataType.STRING : PinotDataType.STRING_ARRAY;
case UUID:
Comment thread
xiangfu0 marked this conversation as resolved.
Preconditions.checkState(singleValue, "UUID array is not supported");
return PinotDataType.UUID;
default:
throw new IllegalStateException("Unsupported DataType: " + type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.apache.calcite.sql.SqlKind;
Expand All @@ -58,6 +59,7 @@
import org.apache.pinot.spi.utils.CommonConstants;
import org.apache.pinot.spi.utils.CommonConstants.Broker.Request;
import org.apache.pinot.spi.utils.TimestampIndexUtils;
import org.apache.pinot.spi.utils.UuidUtils;
import org.apache.pinot.sql.FilterKind;
import org.apache.pinot.sql.parsers.CalciteSqlParser;
import org.apache.pinot.sql.parsers.SqlCompilationException;
Expand Down Expand Up @@ -208,6 +210,9 @@ public static Literal getLiteral(@Nullable Object object) {
if (object instanceof byte[]) {
return getLiteral((byte[]) object);
}
if (object instanceof UUID) {
return getLiteral(UuidUtils.toBytes((UUID) object));
}
if (object instanceof int[]) {
return getLiteral((int[]) object);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.UUID;
import org.apache.pinot.common.request.Literal;
import org.apache.pinot.spi.data.FieldSpec.DataType;
import org.apache.pinot.spi.utils.BigDecimalUtils;
import org.apache.pinot.spi.utils.BytesUtils;
import org.apache.pinot.spi.utils.CommonConstants.NullValuePlaceHolder;
import org.apache.pinot.spi.utils.UuidUtils;
import org.testng.annotations.Test;

import static org.testng.Assert.*;
Expand Down Expand Up @@ -222,4 +224,13 @@ public void testBytesLiteral() {
assertFalse(literalContext.isNull());
assertEquals(literalContext.toString(), "'deadbeef'");
}

@Test
public void testUuidLiteral() {
UUID uuid = UUID.fromString("550e8400-e29b-41d4-a716-446655440000");
LiteralContext literalContext = new LiteralContext(DataType.UUID, uuid);

assertEquals(literalContext.getStringValue(), uuid.toString());
assertEquals(literalContext.getBytesValue(), UuidUtils.toBytes(uuid));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.apache.calcite.sql.SqlDialect;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlLiteral;
Expand All @@ -28,6 +29,8 @@
import org.apache.pinot.common.request.ExpressionType;
import org.apache.pinot.common.request.Function;
import org.apache.pinot.common.request.Identifier;
import org.apache.pinot.common.request.Literal;
import org.apache.pinot.spi.utils.UuidUtils;
import org.apache.pinot.sql.parsers.CalciteSqlParser;
import org.apache.pinot.sql.parsers.PinotSqlType;
import org.apache.pinot.sql.parsers.SqlNodeAndOptions;
Expand Down Expand Up @@ -88,6 +91,25 @@ public void testGetLiteralExpressionForPrimitiveLong() {
assertEquals(literalExpression.getLiteral().getLongValue(), 4500L);
}

@Test
public void testGetLiteralForUuid() {
UUID uuid = UUID.fromString("550e8400-e29b-41d4-a716-446655440000");
Literal literal = RequestUtils.getLiteral(uuid);

assertTrue(literal.isSetBinaryValue());
assertEquals(literal.getBinaryValue(), UuidUtils.toBytes(uuid));
}

@Test
public void testUuidCastFoldsToBinaryLiteral() {
UUID uuid = UUID.fromString("550e8400-e29b-41d4-a716-446655440000");
Expression expression = CalciteSqlParser.compileToPinotQuery(
"SELECT CAST('" + uuid + "' AS UUID) FROM myTable").getSelectList().get(0);

assertTrue(expression.isSetLiteral());
assertEquals(expression.getLiteral().getBinaryValue(), UuidUtils.toBytes(uuid));
}

@Test
public void testParseQuery() {
SqlNodeAndOptions result = RequestUtils.parseQuery("select foo from countries where bar > 1");
Expand Down
Loading