Java 类com.facebook.presto.sql.tree.SetSession 实例源码
项目:presto-query-formatter
文件:StatementFormatter.java
@Override
public Void visitSetSession(SetSession node, Integer indent)
{
builder.append("SET SESSION ")
.append(node.getName())
.append(" = ")
.append(formatExpression(node.getValue(), parameters, indent));
return null;
}
项目:presto
文件:SetSessionTask.java
@Override
public CompletableFuture<?> execute(SetSession statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine)
{
Session session = stateMachine.getSession();
QualifiedName propertyName = statement.getName();
if (propertyName.getParts().size() > 2) {
throw new SemanticException(INVALID_SESSION_PROPERTY, statement, "Invalid session property '%s'", propertyName);
}
PropertyMetadata<?> propertyMetadata = metadata.getSessionPropertyManager().getSessionPropertyMetadata(propertyName.toString());
if (propertyName.getParts().size() == 1) {
accessControl.checkCanSetSystemSessionProperty(session.getIdentity(), propertyName.getParts().get(0));
}
else if (propertyName.getParts().size() == 2) {
accessControl.checkCanSetCatalogSessionProperty(session.getIdentity(), propertyName.getParts().get(0), propertyName.getParts().get(1));
}
Type type = propertyMetadata.getSqlType();
Object objectValue;
try {
objectValue = evaluatePropertyValue(statement.getValue(), type, session, metadata);
}
catch (SemanticException e) {
throw new PrestoException(StandardErrorCode.INVALID_SESSION_PROPERTY,
format("Unable to set session property '%s' to '%s': %s", propertyName, statement.getValue(), e.getMessage()));
}
String value = serializeSessionProperty(type, objectValue);
// verify the SQL value can be decoded by the property
metadata.getSessionPropertyManager().decodeProperty(propertyName.toString(), value, propertyMetadata.getJavaType());
stateMachine.addSetSessionProperties(propertyName.toString(), value);
return completedFuture(null);
}
项目:presto
文件:TestSetSessionTask.java
private void testSetSession(Expression expression, String expectedValue)
throws Exception
{
TransactionManager transactionManager = createTestTransactionManager();
QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "set foo.bar = 'baz'", TEST_SESSION, URI.create("fake://uri"), false, transactionManager, executor);
new SetSessionTask().execute(new SetSession(QualifiedName.of("foo", "bar"), expression), transactionManager, metadata, new AllowAllAccessControl(), stateMachine).join();
Map<String, String> sessionProperties = stateMachine.getSetSessionProperties();
assertEquals(sessionProperties, ImmutableMap.of("foo.bar", expectedValue));
}
项目:presto
文件:SqlFormatter.java
@Override
public Void visitSetSession(SetSession node, Integer context)
{
builder.append("SET SESSION ")
.append(node.getName())
.append(" = ")
.append(formatExpression(node.getValue()));
return null;
}
项目:presto
文件:TestSqlParser.java
@Test
public void testSetSession()
throws Exception
{
assertStatement("SET SESSION foo = 'bar'", new SetSession(QualifiedName.of("foo"), new StringLiteral("bar")));
assertStatement("SET SESSION foo.bar = 'baz'", new SetSession(QualifiedName.of("foo", "bar"), new StringLiteral("baz")));
assertStatement("SET SESSION foo.bar.boo = 'baz'", new SetSession(QualifiedName.of("foo", "bar", "boo"), new StringLiteral("baz")));
assertStatement("SET SESSION foo.bar = 'ban' || 'ana'", new SetSession(
QualifiedName.of("foo", "bar"),
new FunctionCall(QualifiedName.of("concat"), ImmutableList.of(
new StringLiteral("ban"),
new StringLiteral("ana")))));
}
项目:EchoQuery
文件:SqlFormatter.java
@Override
public Void visitSetSession(SetSession node, Integer context)
{
builder.append("SET SESSION ")
.append(node.getName())
.append(" = ")
.append(formatExpression(node.getValue()));
return null;
}
项目:presto
文件:AstBuilder.java
@Override
public Node visitSetSession(SqlBaseParser.SetSessionContext context)
{
return new SetSession(getLocation(context), getQualifiedName(context.qualifiedName()), (Expression) visit(context.expression()));
}