use of io.trino.sql.tree.Identifier in project trino by trinodb.
the class TestSetTimeZoneTask method testSetTimeZoneVarcharFunctionCall.
@Test
public void testSetTimeZoneVarcharFunctionCall() {
QueryStateMachine stateMachine = createQueryStateMachine("SET TIME ZONE concat_ws('/', 'America', 'Los_Angeles')");
SetTimeZone setTimeZone = new SetTimeZone(new NodeLocation(1, 1), Optional.of(new FunctionCall(new NodeLocation(1, 15), QualifiedName.of(ImmutableList.of(new Identifier(new NodeLocation(1, 15), "concat_ws", false))), ImmutableList.of(new StringLiteral(new NodeLocation(1, 25), "/"), new StringLiteral(new NodeLocation(1, 30), "America"), new StringLiteral(new NodeLocation(1, 41), "Los_Angeles")))));
executeSetTimeZone(setTimeZone, stateMachine);
Map<String, String> setSessionProperties = stateMachine.getSetSessionProperties();
assertThat(setSessionProperties).hasSize(1);
assertEquals(setSessionProperties.get(TIME_ZONE_ID), "America/Los_Angeles");
}
use of io.trino.sql.tree.Identifier in project trino by trinodb.
the class TestSetTimeZoneTask method testSetTimeZoneIntervalDayTimeTypeFunctionCall.
@Test
public void testSetTimeZoneIntervalDayTimeTypeFunctionCall() {
QueryStateMachine stateMachine = createQueryStateMachine("SET TIME ZONE parse_duration('8h')");
SetTimeZone setTimeZone = new SetTimeZone(new NodeLocation(1, 1), Optional.of(new FunctionCall(new NodeLocation(1, 24), QualifiedName.of(ImmutableList.of(new Identifier(new NodeLocation(1, 24), "parse_duration", false))), ImmutableList.of(new StringLiteral(new NodeLocation(1, 39), "8h")))));
executeSetTimeZone(setTimeZone, stateMachine);
Map<String, String> setSessionProperties = stateMachine.getSetSessionProperties();
assertThat(setSessionProperties).hasSize(1);
assertEquals(setSessionProperties.get(TIME_ZONE_ID), "+08:00");
}
use of io.trino.sql.tree.Identifier in project trino by trinodb.
the class TestSetPropertiesTask method testSetMaterializedViewProperties.
@Test
public void testSetMaterializedViewProperties() {
QualifiedObjectName materializedViewName = qualifiedObjectName("test_materialized_view");
metadata.createMaterializedView(testSession, materializedViewName, someMaterializedView(), false, false);
// set all properties to non-DEFAULT values and check the results
executeSetProperties(new SetProperties(MATERIALIZED_VIEW, asQualifiedName(materializedViewName), ImmutableList.of(new Property(new Identifier(MATERIALIZED_VIEW_PROPERTY_1_NAME), new LongLiteral("111")), new Property(new Identifier(MATERIALIZED_VIEW_PROPERTY_2_NAME), new StringLiteral("abc")))));
assertThat(metadata.getMaterializedView(testSession, materializedViewName).get().getProperties()).isEqualTo(ImmutableMap.of(MATERIALIZED_VIEW_PROPERTY_1_NAME, 111L, MATERIALIZED_VIEW_PROPERTY_2_NAME, "abc"));
// set all properties to DEFAULT and check the results
executeSetProperties(new SetProperties(MATERIALIZED_VIEW, asQualifiedName(materializedViewName), ImmutableList.of(new Property(new Identifier(MATERIALIZED_VIEW_PROPERTY_1_NAME)), new Property(new Identifier(MATERIALIZED_VIEW_PROPERTY_2_NAME)))));
// since the default value of property 1 is null, property 1 should not appear in the result, whereas property 2 should appear in
// the result with its (non-null) default value
assertThat(metadata.getMaterializedView(testSession, materializedViewName).get().getProperties()).isEqualTo(ImmutableMap.of(MATERIALIZED_VIEW_PROPERTY_2_NAME, MATERIALIZED_VIEW_PROPERTY_2_DEFAULT_VALUE));
}
use of io.trino.sql.tree.Identifier in project trino by trinodb.
the class GrantRolesTask method execute.
@Override
public ListenableFuture<Void> execute(GrantRoles statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
Session session = stateMachine.getSession();
Set<String> roles = statement.getRoles().stream().map(role -> role.getValue().toLowerCase(Locale.ENGLISH)).collect(toImmutableSet());
Set<TrinoPrincipal> grantees = statement.getGrantees().stream().map(MetadataUtil::createPrincipal).collect(toImmutableSet());
boolean adminOption = statement.isAdminOption();
Optional<TrinoPrincipal> grantor = statement.getGrantor().map(specification -> createPrincipal(session, specification));
Optional<String> catalog = processRoleCommandCatalog(metadata, session, statement, statement.getCatalog().map(Identifier::getValue));
Set<String> specifiedRoles = new LinkedHashSet<>();
specifiedRoles.addAll(roles);
grantees.stream().filter(principal -> principal.getType() == ROLE).map(TrinoPrincipal::getName).forEach(specifiedRoles::add);
if (grantor.isPresent() && grantor.get().getType() == ROLE) {
specifiedRoles.add(grantor.get().getName());
}
for (String role : specifiedRoles) {
checkRoleExists(session, statement, metadata, role, catalog);
}
accessControl.checkCanGrantRoles(session.toSecurityContext(), roles, grantees, adminOption, grantor, catalog);
metadata.grantRoles(session, roles, grantees, adminOption, grantor, catalog);
return immediateVoidFuture();
}
use of io.trino.sql.tree.Identifier in project trino by trinodb.
the class ScopeAware method scopeAwareHash.
private OptionalInt scopeAwareHash(Node node) {
if (node instanceof Expression) {
Expression expression = (Expression) node;
if (analysis.isColumnReference(expression)) {
ResolvedField field = analysis.getResolvedField(expression);
Scope resolvedScope = field.getScope();
if (resolvedScope.hasOuterParent(queryScope)) {
return OptionalInt.of(treeHash(expression, CanonicalizationAware::canonicalizationAwareHash));
}
return OptionalInt.of(field.getFieldId().hashCode());
} else if (expression instanceof Identifier) {
return OptionalInt.of(treeHash(expression, CanonicalizationAware::canonicalizationAwareHash));
} else if (node.getChildren().isEmpty()) {
// Calculate shallow hash since node doesn't have any children
return OptionalInt.of(expression.hashCode());
}
}
return OptionalInt.empty();
}
Aggregations