Skip to content

Commit

Permalink
Internal Query : Fix Remove Antlr dependency for now (#1626)
Browse files Browse the repository at this point in the history
* backing out Antlr dependancy for now

* removed check for zero query plan calls
  • Loading branch information
bchong95 committed Jun 17, 2020
1 parent 1785ee0 commit ed7faae
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 18 deletions.
1 change: 0 additions & 1 deletion Microsoft.Azure.Cosmos/src/Microsoft.Azure.Cosmos.csproj
Expand Up @@ -82,7 +82,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Antlr4.Runtime.Standard" Version="4.8.0" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
Expand Down
34 changes: 18 additions & 16 deletions Microsoft.Azure.Cosmos/src/Query/Core/Parser/CstToAstVisitor.cs
Expand Up @@ -4,6 +4,7 @@

namespace Microsoft.Azure.Cosmos.Query.Core.Parser
{
#if false
using System;
using System.Collections.Generic;
using Antlr4.Runtime.Tree;
Expand Down Expand Up @@ -126,7 +127,7 @@ public override SqlObject VisitSql_query(sqlParser.Sql_queryContext context)
sqlOffsetLimitClause);
}

#region SELECT
#region SELECT
public override SqlObject VisitSelect_clause(sqlParser.Select_clauseContext context)
{
SqlSelectSpec sqlSelectSpec = (SqlSelectSpec)this.Visit(context.selection());
Expand Down Expand Up @@ -200,8 +201,8 @@ public override SqlObject VisitTop_spec(sqlParser.Top_specContext context)
Number64 topCount = CstToAstVisitor.GetNumber64ValueFromNode(context.NUMERIC_LITERAL());
return SqlTopSpec.Create(SqlNumberLiteral.Create(topCount));
}
#endregion
#region FROM
#endregion
#region FROM
public override SqlObject VisitFrom_clause(sqlParser.From_clauseContext context)
{
Contract.Requires(context != null);
Expand Down Expand Up @@ -310,16 +311,16 @@ public override SqlObject VisitStringPathExpression(sqlParser.StringPathExpressi

return SqlStringPathExpression.Create(pathExpression, stringIndex);
}
#endregion
#region WHERE
#endregion
#region WHERE
public override SqlObject VisitWhere_clause(sqlParser.Where_clauseContext context)
{
Contract.Requires(context != null);
SqlScalarExpression sqlScalarExpression = (SqlScalarExpression)this.Visit(context.scalar_expression());
return SqlWhereClause.Create(sqlScalarExpression);
}
#endregion
#region GROUP BY
#endregion
#region GROUP BY
public override SqlObject VisitGroup_by_clause(sqlParser.Group_by_clauseContext context)
{
Contract.Requires(context != null);
Expand All @@ -332,8 +333,8 @@ public override SqlObject VisitGroup_by_clause(sqlParser.Group_by_clauseContext

return SqlGroupByClause.Create(groupByColumns);
}
#endregion
#region ORDER BY
#endregion
#region ORDER BY
public override SqlObject VisitOrder_by_clause(sqlParser.Order_by_clauseContext context)
{
Contract.Requires(context != null);
Expand Down Expand Up @@ -365,8 +366,8 @@ public override SqlObject VisitOrder_by_clause(sqlParser.Order_by_clauseContext

return SqlOrderbyClause.Create(orderByItems);
}
#endregion
#region OFFSET LIMIT
#endregion
#region OFFSET LIMIT
public override SqlObject VisitOffset_limit_clause(sqlParser.Offset_limit_clauseContext context)
{
Contract.Requires(context != null);
Expand All @@ -383,8 +384,8 @@ public override SqlObject VisitOffset_limit_clause(sqlParser.Offset_limit_clause

return SqlOffsetLimitClause.Create(sqlOffsetSpec, sqlLimitSpec);
}
#endregion
#region ScalarExpressions
#endregion
#region ScalarExpressions
public override SqlObject VisitArrayCreateScalarExpression(sqlParser.ArrayCreateScalarExpressionContext context)
{
Contract.Requires(context != null);
Expand Down Expand Up @@ -637,9 +638,9 @@ public override SqlObject VisitUnaryScalarExpression(sqlParser.UnaryScalarExpres

return SqlUnaryScalarExpression.Create(unaryOperator, expression);
}
#endregion
#endregion

#region NOT IMPLEMENTED ON PURPOSE
#region NOT IMPLEMENTED ON PURPOSE
public override SqlObject VisitBinary_operator(sqlParser.Binary_operatorContext context)
{
throw new NotSupportedException();
Expand Down Expand Up @@ -689,7 +690,7 @@ public override SqlObject VisitScalar_expression_list(sqlParser.Scalar_expressio
{
throw new NotSupportedException();
}
#endregion
#endregion

private sealed class UnknownSqlObjectException : ArgumentOutOfRangeException
{
Expand Down Expand Up @@ -724,4 +725,5 @@ private static Number64 GetNumber64ValueFromNode(IParseTree parseTree)
return number64;
}
}
#endif
}
2 changes: 2 additions & 0 deletions Microsoft.Azure.Cosmos/src/Query/Core/Parser/ErrorListener.cs
Expand Up @@ -6,6 +6,7 @@

namespace Microsoft.Azure.Cosmos.Query.Core.Parser
{
#if false
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -66,4 +67,5 @@ public ErrorListener(Parser parser, Lexer lexer, CommonTokenStream token_stream)
base.SyntaxError(output, recognizer, offendingSymbol, line, col, msg, e);
}
}
#endif
}
2 changes: 2 additions & 0 deletions Microsoft.Azure.Cosmos/src/Query/Core/Parser/IsqlListener.cs
Expand Up @@ -21,6 +21,7 @@

namespace Microsoft.Azure.Cosmos.Query.Core.Parser
{
#if false
using Antlr4.Runtime.Misc;
using IParseTreeListener = Antlr4.Runtime.Tree.IParseTreeListener;

Expand Down Expand Up @@ -582,4 +583,5 @@ internal interface IsqlListener : IParseTreeListener
/// <param name="context">The parse tree.</param>
void ExitLiteral([NotNull] sqlParser.LiteralContext context);
}
#endif
}
2 changes: 2 additions & 0 deletions Microsoft.Azure.Cosmos/src/Query/Core/Parser/IsqlVisitor.cs
Expand Up @@ -21,6 +21,7 @@

namespace Microsoft.Azure.Cosmos.Query.Core.Parser
{
#if false
using Antlr4.Runtime.Misc;
using Antlr4.Runtime.Tree;
using IToken = Antlr4.Runtime.IToken;
Expand Down Expand Up @@ -359,4 +360,5 @@ internal interface IsqlVisitor<Result> : IParseTreeVisitor<Result>
/// <return>The visitor result.</return>
Result VisitLiteral([NotNull] sqlParser.LiteralContext context);
}
#endif
}
3 changes: 3 additions & 0 deletions Microsoft.Azure.Cosmos/src/Query/Core/Parser/LASets.cs
Expand Up @@ -6,6 +6,7 @@

namespace Microsoft.Azure.Cosmos.Query.Core.Parser
{
#if false
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -17,6 +18,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Parser

internal class LASets
{

private readonly Dictionary<Pair<ATNState, int>, bool> visited = new Dictionary<Pair<ATNState, int>, bool>();
private readonly bool logParse = false;
private readonly bool logClosure = false;
Expand Down Expand Up @@ -795,4 +797,5 @@ private string PrintResult(List<List<Edge>> all_parses)
return sb.ToString();
}
}
#endif
}
Expand Up @@ -21,6 +21,7 @@

namespace Microsoft.Azure.Cosmos.Query.Core.Parser
{
#if false
using Antlr4.Runtime.Misc;
using Antlr4.Runtime.Tree;

Expand Down Expand Up @@ -562,4 +563,5 @@ internal partial class sqlBaseVisitor<Result> : AbstractParseTreeVisitor<Result>
/// <return>The visitor result.</return>
public virtual Result VisitLiteral([NotNull] sqlParser.LiteralContext context) { return VisitChildren(context); }
}
#endif
}
2 changes: 2 additions & 0 deletions Microsoft.Azure.Cosmos/src/Query/Core/Parser/sqlLexer.cs
Expand Up @@ -21,6 +21,7 @@

namespace Microsoft.Azure.Cosmos.Query.Core.Parser
{
#if false
using System;
using System.IO;
using Antlr4.Runtime;
Expand Down Expand Up @@ -562,4 +563,5 @@ static sqlLexer()
public static readonly ATN _ATN =
new ATNDeserializer().Deserialize(_serializedATN);
}
#endif
}
4 changes: 3 additions & 1 deletion Microsoft.Azure.Cosmos/src/Query/Core/Parser/sqlParser.cs
Expand Up @@ -21,6 +21,7 @@

namespace Microsoft.Azure.Cosmos.Query.Core.Parser
{
#if false
using System;
using System.IO;
using Antlr4.Runtime;
Expand Down Expand Up @@ -3325,4 +3326,5 @@ private bool scalar_expression_sempred(Scalar_expressionContext _localctx, int p
public static readonly ATN _ATN =
new ATNDeserializer().Deserialize(_serializedATN);
}
}
#endif
}
9 changes: 9 additions & 0 deletions Microsoft.Azure.Cosmos/src/SqlObjects/SqlQuery.cs
Expand Up @@ -5,8 +5,10 @@ namespace Microsoft.Azure.Cosmos.Sql
{
using System;
using System.Runtime.ExceptionServices;
#if false
using Antlr4.Runtime;
using Antlr4.Runtime.Misc;
#endif
using Microsoft.Azure.Cosmos.Query.Core.Parser;

internal sealed class SqlQuery : SqlObject
Expand Down Expand Up @@ -66,6 +68,7 @@ public static bool TryParse(string text, out SqlQuery sqlQuery)
throw new ArgumentNullException(nameof(text));
}

#if false
AntlrInputStream str = new AntlrInputStream(text);
sqlLexer lexer = new sqlLexer(str);
CommonTokenStream tokens = new CommonTokenStream(lexer);
Expand Down Expand Up @@ -95,8 +98,13 @@ public static bool TryParse(string text, out SqlQuery sqlQuery)

sqlQuery = (SqlQuery)CstToAstVisitor.Singleton.Visit(programContext);
return true;
#else
sqlQuery = default;
return false;
#endif
}

#if false
private sealed class ThrowExceptionOnErrors : IAntlrErrorStrategy
{
public static readonly ThrowExceptionOnErrors Singleton = new ThrowExceptionOnErrors();
Expand Down Expand Up @@ -137,5 +145,6 @@ public void Sync(Parser recognizer)
// Do nothing
}
}
#endif
}
}
Expand Up @@ -675,10 +675,12 @@ async Task<List<CosmosElement>> AssertPassthroughAsync(string query, Cosmos.Part
Assert.IsTrue(feedOptions.TestSettings.Stats.PipelineType.HasValue);
Assert.AreEqual(TestInjections.PipelineType.Passthrough, feedOptions.TestSettings.Stats.PipelineType.Value);

#if false
if (pk.HasValue)
{
Assert.AreEqual(0, cosmosQueryClientCore.QueryPlanCalls);
}
#endif

return queryResults;
}
Expand Down

0 comments on commit ed7faae

Please sign in to comment.