use of io.crate.sql.tree.StringLiteral in project crate by crate.
the class RepositoryParamValidatorTest method testS3ConfigParams.
@Test
public void testS3ConfigParams() throws Exception {
GenericProperties genericProperties = new GenericProperties();
genericProperties.add(new GenericProperty("access_key", new StringLiteral("foobar")));
genericProperties.add(new GenericProperty("base_path", new StringLiteral("/data")));
genericProperties.add(new GenericProperty("bucket", new StringLiteral("myBucket")));
genericProperties.add(new GenericProperty("buffer_size", new StringLiteral("10k")));
genericProperties.add(new GenericProperty("canned_acl", new StringLiteral("cannedACL")));
genericProperties.add(new GenericProperty("chunk_size", new StringLiteral("4g")));
genericProperties.add(new GenericProperty("compress", new StringLiteral("true")));
genericProperties.add(new GenericProperty("concurrent_streams", new StringLiteral("12")));
genericProperties.add(new GenericProperty("endpoint", new StringLiteral("myEndpoint")));
genericProperties.add(new GenericProperty("max_retries", new StringLiteral("8")));
genericProperties.add(new GenericProperty("protocol", new StringLiteral("myProtocol")));
genericProperties.add(new GenericProperty("region", new StringLiteral("Europe-1")));
genericProperties.add(new GenericProperty("secret_key", new StringLiteral("thisIsASecretKey")));
genericProperties.add(new GenericProperty("server_side_encryption", new StringLiteral("false")));
Settings settings = validator.convertAndValidate("s3", Optional.of(genericProperties), ParameterContext.EMPTY);
assertThat(settings.get("access_key"), is("foobar"));
assertThat(settings.get("base_path"), is("/data"));
assertThat(settings.get("bucket"), is("myBucket"));
assertThat(settings.get("buffer_size"), is("10240b"));
assertThat(settings.get("canned_acl"), is("cannedACL"));
assertThat(settings.get("chunk_size"), is("4294967296b"));
assertThat(settings.get("compress"), is("true"));
assertThat(settings.get("concurrent_streams"), is("12"));
assertThat(settings.get("endpoint"), is("myEndpoint"));
assertThat(settings.get("max_retries"), is("8"));
assertThat(settings.get("protocol"), is("myProtocol"));
assertThat(settings.get("region"), is("Europe-1"));
assertThat(settings.get("secret_key"), is("thisIsASecretKey"));
assertThat(settings.get("server_side_encryption"), is("false"));
}
use of io.crate.sql.tree.StringLiteral in project crate by crate.
the class RepositoryParamValidatorTest method testInvalidSetting.
@Test
public void testInvalidSetting() throws Exception {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("setting 'yay' not supported");
GenericProperties genericProperties = new GenericProperties();
genericProperties.add(new GenericProperty("location", new StringLiteral("foo")));
genericProperties.add(new GenericProperty("yay", new StringLiteral("invalid")));
validator.convertAndValidate("fs", Optional.of(genericProperties), ParameterContext.EMPTY);
}
use of io.crate.sql.tree.StringLiteral in project crate by crate.
the class TestStatementBuilder method testSubscriptExpression.
@Test
public void testSubscriptExpression() {
Expression expression = SqlParser.createExpression("a['sub']");
assertThat(expression, instanceOf(SubscriptExpression.class));
SubscriptExpression subscript = (SubscriptExpression) expression;
assertThat(subscript.index(), instanceOf(StringLiteral.class));
assertThat(((StringLiteral) subscript.index()).getValue(), is("sub"));
assertThat(subscript.base(), instanceOf(QualifiedNameReference.class));
expression = SqlParser.createExpression("[1,2,3][1]");
assertThat(expression, instanceOf(SubscriptExpression.class));
subscript = (SubscriptExpression) expression;
assertThat(subscript.index(), instanceOf(IntegerLiteral.class));
assertThat(((IntegerLiteral) subscript.index()).getValue(), is(1));
assertThat(subscript.base(), instanceOf(ArrayLiteral.class));
}
use of io.crate.sql.tree.StringLiteral in project crate by crate.
the class AstBuilder method visitMaybeParametrizedDataType.
@Override
public Node visitMaybeParametrizedDataType(SqlBaseParser.MaybeParametrizedDataTypeContext context) {
StringLiteral name = (StringLiteral) visit(context.baseDataType());
var parameters = new ArrayList<Integer>(context.integerLiteral().size());
for (var param : context.integerLiteral()) {
var literal = visit(param);
int val;
if (literal instanceof LongLiteral) {
val = Math.toIntExact(((LongLiteral) literal).getValue());
} else {
val = ((IntegerLiteral) literal).getValue();
}
parameters.add(val);
}
return new ColumnType<>(name.getValue(), parameters);
}
use of io.crate.sql.tree.StringLiteral in project crate by crate.
the class DeallocateAnalyzer method analyze.
public static AnalyzedDeallocate analyze(DeallocateStatement deallocateStatement) {
Expression preparedStmtExpression = deallocateStatement.preparedStmt();
String preparedStmt = null;
if (preparedStmtExpression != null) {
if (preparedStmtExpression instanceof StringLiteral) {
preparedStmt = ((StringLiteral) preparedStmtExpression).getValue();
} else if (preparedStmtExpression instanceof QualifiedNameReference) {
preparedStmt = ((QualifiedNameReference) preparedStmtExpression).getName().toString();
} else {
throw new AssertionError("Expression " + preparedStmtExpression.toString() + " not supported as " + "preparedStmt expression for DEALLOCATE");
}
}
return new AnalyzedDeallocate(preparedStmt);
}
Aggregations