public override SqlObject Visit(SqlSelectListSpec sqlSelectListSpec) { List <SqlSelectItem> items = new List <SqlSelectItem>(); foreach (SqlSelectItem item in sqlSelectListSpec.Items) { items.Add(item.Accept(this) as SqlSelectItem); } return(SqlSelectListSpec.Create(items.ToImmutableArray())); }
public override SqlSelectSpec Visit(SqlSelectListSpec selectSpec) { List <SqlSelectItem> selectItems = new List <SqlSelectItem>(); foreach (SqlSelectItem selectItem in selectSpec.Items) { selectItems.Add(SqlSelectItem.Create( selectItem.Expression.Accept(this.scalarExpressionTransformer), selectItem.Alias)); } return(SqlSelectListSpec.Create(selectItems)); }
public override SqlObject VisitSelect_list_spec([NotNull] sqlParser.Select_list_specContext context) { Contract.Requires(context != null); List <SqlSelectItem> sqlSelectItems = new List <SqlSelectItem>(); foreach (sqlParser.Select_itemContext selectItemContext in context.select_item()) { SqlSelectItem selectItem = (SqlSelectItem)this.Visit(selectItemContext); sqlSelectItems.Add(selectItem); } return(SqlSelectListSpec.Create(sqlSelectItems.ToImmutableArray())); }
public void SqlSelectListSpecTest() { CosmosObject john = CosmosObject.Create(new Dictionary <string, CosmosElement> { ["name"] = CosmosString.Create("John"), ["age"] = CosmosNumber64.Create(25) }); CosmosObject johnWrapped = CosmosObject.Create(new Dictionary <string, CosmosElement> { ["c"] = john }); // { c.name, c.age } SqlScalarExpression cDotName = TestUtils.CreatePathExpression("c", "name"); SqlScalarExpression cDotAge = TestUtils.CreatePathExpression("c", "age"); SqlSelectListSpec listSpec = SqlSelectListSpec.Create( SqlSelectItem.Create(cDotName), SqlSelectItem.Create(cDotAge)); AssertEvaluation(john, listSpec, johnWrapped); // { c.name AS nameAlias } CosmosObject johnAliased = CosmosObject.Create(new Dictionary <string, CosmosElement> { ["nameAlias"] = CosmosString.Create("John"), }); SqlSelectListSpec listSpecWithAlias = SqlSelectListSpec.Create(SqlSelectItem.Create(cDotName, SqlIdentifier.Create("nameAlias"))); AssertEvaluation(johnAliased, listSpecWithAlias, johnWrapped); // { 3 + 5 } CosmosObject johnNonPropertyName = CosmosObject.Create(new Dictionary <string, CosmosElement> { ["$1"] = CosmosNumber64.Create(8) }); SqlLiteralScalarExpression five = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(5)); SqlLiteralScalarExpression three = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(3)); SqlBinaryScalarExpression fivePlusThree = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Add, five, three); SqlSelectListSpec listSpecNonMember = SqlSelectListSpec.Create(SqlSelectItem.Create(fivePlusThree)); AssertEvaluation(johnNonPropertyName, listSpecNonMember); // { 3 + 5 AS Five Plus Three } CosmosObject johnNonPropertyNameAliased = CosmosObject.Create(new Dictionary <string, CosmosElement> { ["Five Plus Three"] = CosmosNumber64.Create(8) }); SqlSelectListSpec listSpecNonMemberAliased = SqlSelectListSpec.Create(SqlSelectItem.Create(fivePlusThree, SqlIdentifier.Create("Five Plus Three"))); AssertEvaluation(johnNonPropertyNameAliased, listSpecNonMemberAliased); // { c.blah[0] } CosmosObject numberIndex = CosmosObject.Create(new Dictionary <string, CosmosElement> { ["blah"] = CosmosArray.Create( new List <CosmosElement>() { CosmosNumber64.Create(0), CosmosNumber64.Create(1), CosmosNumber64.Create(2) }) }); CosmosObject numberIndexWrapped = CosmosObject.Create(new Dictionary <string, CosmosElement> { ["c"] = numberIndex }); CosmosObject numberIndexEval = CosmosObject.Create(new Dictionary <string, CosmosElement> { ["$1"] = CosmosNumber64.Create(0) }); SqlScalarExpression cDotBlah0 = TestUtils.CreatePathExpression("c", "blah", 0); SqlSelectListSpec numberIndexSpec = SqlSelectListSpec.Create(SqlSelectItem.Create(cDotBlah0)); AssertEvaluation(numberIndexEval, numberIndexSpec, numberIndexWrapped); }