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 @@ -19,7 +19,6 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap;
import com.google.common.collect.Streams;
import io.airlift.slice.SliceUtf8;
import io.trino.Session;
import io.trino.execution.warnings.WarningCollector;
import io.trino.metadata.BoundSignature;
Expand Down Expand Up @@ -478,11 +477,6 @@ public Multimap<QualifiedObjectName, String> getTableColumnReferences()
return tableColumnReferences;
}

public Multimap<NodeRef<Node>, Field> getReferencedFields()
{
return referencedFields;
}

public List<Field> getSourceFields()
{
return sourceFields;
Expand Down Expand Up @@ -982,14 +976,14 @@ protected Type visitArrayConstructor(ArrayConstructor node, StackableAstVisitorC
@Override
protected Type visitStringLiteral(StringLiteral node, StackableAstVisitorContext<Context> context)
{
VarcharType type = VarcharType.createVarcharType(SliceUtf8.countCodePoints(node.getSlice()));
VarcharType type = VarcharType.createVarcharType(node.length());
return setExpressionType(node, type);
}

@Override
protected Type visitCharLiteral(CharLiteral node, StackableAstVisitorContext<Context> context)
{
CharType type = CharType.createCharType(node.getValue().length());
CharType type = CharType.createCharType(node.length());
return setExpressionType(node, type);
}

Expand Down Expand Up @@ -2212,7 +2206,7 @@ protected Type visitInPredicate(InPredicate node, StackableAstVisitorContext<Con
.ifPresent(function -> {
throw semanticException(NOT_SUPPORTED, function, "IN-PREDICATE with %s function is not yet supported", function.getName().getSuffix());
});
extractExpressions(ImmutableList.of(value), DereferenceExpression.class).stream()
extractExpressions(ImmutableList.of(value), DereferenceExpression.class)
.forEach(dereference -> {
QualifiedName qualifiedName = DereferenceExpression.getQualifiedName(dereference);
if (qualifiedName != null) {
Expand Down Expand Up @@ -2603,7 +2597,7 @@ private void addOrReplaceExpressionCoercion(Expression expression, Type type, Ty
if (typeCoercion.isTypeOnlyCoercion(type, superType)) {
typeOnlyCoercions.add(ref);
}
else if (typeOnlyCoercions.contains(ref)) {
else {
typeOnlyCoercions.remove(ref);
}
}
Expand Down Expand Up @@ -2868,8 +2862,7 @@ private static void updateAnalysis(Analysis analysis, ExpressionAnalyzer analyze
analyzer.getSortKeyCoercionsForFrameBoundCalculation(),
analyzer.getSortKeyCoercionsForFrameBoundComparison());
analysis.addFrameBoundCalculations(analyzer.getFrameBoundCalculations());
analyzer.getResolvedFunctions().entrySet()
.forEach(entry -> analysis.addResolvedFunction(entry.getKey().getNode(), entry.getValue(), session.getUser()));
analyzer.getResolvedFunctions().forEach((key, value) -> analysis.addResolvedFunction(key.getNode(), value, session.getUser()));
analysis.addColumnReferences(analyzer.getColumnReferences());
analysis.addLambdaArgumentReferences(analyzer.getLambdaArgumentReferences());
analysis.addTableColumnReferences(accessControl, session.getIdentity(), analyzer.getTableColumnReferences());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ protected Optional<ConnectorExpression> visitBooleanLiteral(BooleanLiteral node,
@Override
protected Optional<ConnectorExpression> visitStringLiteral(StringLiteral node, Void context)
{
return Optional.of(new Constant(node.getSlice(), typeOf(node)));
return Optional.of(new Constant(Slices.utf8Slice(node.getValue()), typeOf(node)));
}

@Override
Expand All @@ -477,13 +477,13 @@ protected Optional<ConnectorExpression> visitDecimalLiteral(DecimalLiteral node,
@Override
protected Optional<ConnectorExpression> visitCharLiteral(CharLiteral node, Void context)
{
return Optional.of(new Constant(node.getSlice(), typeOf(node)));
return Optional.of(new Constant(Slices.utf8Slice(node.getValue()), typeOf(node)));
}

@Override
protected Optional<ConnectorExpression> visitBinaryLiteral(BinaryLiteral node, Void context)
{
return Optional.of(new Constant(node.getValue(), typeOf(node)));
return Optional.of(new Constant(Slices.wrappedBuffer(node.getValue()), typeOf(node)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1004,10 +1004,11 @@ private Optional<ExtractionResult> tryVisitLikePredicate(LikePredicate node, Boo
VarcharType varcharType = (VarcharType) type;

Symbol symbol = Symbol.from(node.getValue());
Slice pattern = ((StringLiteral) node.getPattern()).getSlice();
Slice pattern = Slices.utf8Slice(((StringLiteral) node.getPattern()).getValue());
Optional<Slice> escape = node.getEscape()
.map(StringLiteral.class::cast)
.map(StringLiteral::getSlice);
.map(StringLiteral::getValue)
.map(Slices::utf8Slice);

int patternConstantPrefixBytes = LikeFunctions.patternConstantPrefixBytes(pattern, escape);
if (patternConstantPrefixBytes == pattern.length()) {
Expand Down Expand Up @@ -1077,7 +1078,7 @@ private Optional<ExtractionResult> tryVisitStartsWithFunction(FunctionCall node,
}

Symbol symbol = Symbol.from(target);
Slice constantPrefix = ((StringLiteral) prefix).getSlice();
Slice constantPrefix = Slices.utf8Slice(((StringLiteral) prefix).getValue());

return createRangeDomain(type, constantPrefix).map(domain -> new ExtractionResult(TupleDomain.withColumnDomains(ImmutableMap.of(symbol, domain)), node));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.primitives.Primitives;
import io.airlift.slice.Slice;
import io.airlift.slice.Slices;
import io.trino.Session;
import io.trino.execution.warnings.WarningCollector;
import io.trino.metadata.FunctionNullability;
Expand Down Expand Up @@ -1211,11 +1212,11 @@ private JoniRegexp getConstantPattern(LikePredicate node)
StringLiteral pattern = (StringLiteral) node.getPattern();

if (node.getEscape().isPresent()) {
Slice escape = ((StringLiteral) node.getEscape().get()).getSlice();
result = LikeFunctions.likePattern(pattern.getSlice(), escape);
Slice escape = Slices.utf8Slice(((StringLiteral) node.getEscape().get()).getValue());
result = LikeFunctions.likePattern(Slices.utf8Slice(pattern.getValue()), escape);
}
else {
result = LikeFunctions.compileLikePattern(pattern.getSlice());
result = LikeFunctions.compileLikePattern(Slices.utf8Slice(pattern.getValue()));
}

likePatternCache.put(node, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.google.common.collect.ImmutableList;
import io.airlift.slice.Slice;
import io.airlift.slice.Slices;
import io.trino.Session;
import io.trino.metadata.ResolvedFunction;
import io.trino.spi.connector.ConnectorSession;
Expand Down Expand Up @@ -125,19 +126,19 @@ protected Object visitDecimalLiteral(DecimalLiteral node, Void context)
@Override
protected Slice visitStringLiteral(StringLiteral node, Void context)
{
return node.getSlice();
return Slices.utf8Slice(node.getValue());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, StringLiteral contains Slice for performance reasons.
so this is not an OK change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep byte[] instead there and only wrap as Slice in relevant places?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It used to matter when the evaluation engine relied on interpreting the AST for every row. That hasn't been the case for many years.

See previous comment: #5649 (comment)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep byte[] instead there and only wrap as Slice in relevant places?

This is not needed. The conversions from String in the analyzer/planner don't happen often enough for it to be a meaningful performance issue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me benchmark Slice w/ String vs String vs byte[] with String view method

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm benchmarking, so we will be able to compare numbers

}

@Override
protected Object visitCharLiteral(CharLiteral node, Void context)
{
return node.getSlice();
return Slices.utf8Slice(node.getValue());
}

@Override
protected Slice visitBinaryLiteral(BinaryLiteral node, Void context)
{
return node.getValue();
return Slices.wrappedBuffer(node.getValue());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
import java.util.Map;

import static com.google.common.collect.ImmutableList.toImmutableList;
import static io.airlift.slice.SliceUtf8.countCodePoints;
import static io.airlift.slice.Slices.utf8Slice;
import static io.airlift.slice.Slices.wrappedBuffer;
import static io.trino.spi.function.OperatorType.EQUAL;
import static io.trino.spi.function.OperatorType.HASH_CODE;
import static io.trino.spi.function.OperatorType.INDETERMINATE;
Expand Down Expand Up @@ -228,19 +228,19 @@ protected RowExpression visitDecimalLiteral(DecimalLiteral node, Void context)
@Override
protected RowExpression visitStringLiteral(StringLiteral node, Void context)
{
return constant(node.getSlice(), createVarcharType(countCodePoints(node.getSlice())));
return constant(utf8Slice(node.getValue()), createVarcharType(node.length()));
}

@Override
protected RowExpression visitCharLiteral(CharLiteral node, Void context)
{
return constant(node.getSlice(), createCharType(node.getValue().length()));
return constant(utf8Slice(node.getValue()), createCharType(node.length()));
}

@Override
protected RowExpression visitBinaryLiteral(BinaryLiteral node, Void context)
{
return constant(node.getValue(), VARBINARY);
return constant(wrappedBuffer(node.getValue()), VARBINARY);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1895,14 +1895,7 @@ private static void assertLike(byte[] value, String pattern, boolean expected)

private static StringLiteral rawStringLiteral(Slice slice)
{
return new StringLiteral(slice.toStringUtf8())
{
@Override
public Slice getSlice()
{
return slice;
}
};
return new StringLiteral(slice.toStringUtf8());
}

private static void assertOptimizedEquals(@Language("SQL") String actual, @Language("SQL") String expected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ protected Boolean visitStringLiteral(StringLiteral actual, Node expectedExpressi
return false;
}

StringLiteral expected = (StringLiteral) expectedExpression;

return actual.getValue().equals(expected.getValue());
return getValueFromLiteral(actual).equals(getValueFromLiteral(expectedExpression));
}

@Override
Expand Down Expand Up @@ -203,6 +201,10 @@ private static String getValueFromLiteral(Node expression)
return ((GenericLiteral) expression).getValue();
}

if (expression instanceof StringLiteral) {
return ((StringLiteral) expression).getValue();
}

throw new IllegalArgumentException("Unsupported literal expression type: " + expression.getClass().getName());
}

Expand Down
5 changes: 0 additions & 5 deletions core/trino-parser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
</properties>

<dependencies>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>slice</artifactId>
</dependency>

<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
Expand Down
Loading