Skip to content

Commit

Permalink
[Internal] Query: Adds deserializing logic for ClientQL Coordinator D…
Browse files Browse the repository at this point in the history
…istribution Plan (#3988)

* First commit.

* Added remaining classes for ClientQL structure

* Added ClientQLDeserializing class and added CoordinatorDistributionPlan folder

* Added support for all Enumerable and Scalar Expressions

* Added baseline tests for testing CoordinatorDistributionPlan deserializing

* Made ClientQL objects immutable

* Added error and null checks for Value calls

* Updated List<> with IReadOnlyList<>

* Made most functions in the Deserializing class private and static

* Added static constant class for Enumerable expressions

* Added null checking for arrays

* Removed null checks from deserializing array functions

* Removed support for JavaScript

* Removed support for Unwind

* Function names changed

* Removed few functions.

* Updated constants class

* Function Formatting for ClientQL Deserializing (#4062)

* Adding error handling for Deserializing functions

* Finished updating code to remove all dependency on Newtonsoft.Json

* Removed try catch for all upper level functions

* Resolved comments

* Resolved comments pt2

* Updated error message

* Resolved comments pt3

* Changed parameter types from int to long

* Removed ClientQLDelegate

* Syntax Fixes

* Removed ClientQLFlattenEnumerable file. This is JS.

* Fixed List helper functions

* Made singleton constructors from public to private

* Updated the DeserializeClientQLBinaryLiteral function

* Renamed ClientQL to QL

* Fixed variable names

* Updated more variable names

* Removed support for Type

* Removed all extra newlines

* Added null checks

* Updated the name CoordinatorDistributionPlan to ClientDistributionPlan

* Removed all support for Cassandra, Mongo and Binary Literal

* Updaed ClientQL to Cql

* Updated baseline test class property.
  • Loading branch information
akotalwar authored Sep 26, 2023
1 parent 08e7f54 commit 4556567
Show file tree
Hide file tree
Showing 59 changed files with 2,502 additions and 0 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Query.Core.ClientDistributionPlan.Cql
{
using System;

internal class ClientDistributionPlan
{
public ClientDistributionPlan(CqlEnumerableExpression cql)
{
this.Cql = cql ?? throw new ArgumentNullException(nameof(cql));
}

public CqlEnumerableExpression Cql { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Query.Core.ClientDistributionPlan.Cql
{
internal abstract class CqlAggregate
{
protected CqlAggregate(CqlAggregateKind kind)
{
this.Kind = kind;
}

public CqlAggregateKind Kind { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Query.Core.ClientDistributionPlan.Cql
{
using System;

internal class CqlAggregateEnumerableExpression : CqlEnumerableExpression
{
public CqlAggregateEnumerableExpression(CqlEnumerableExpression sourceExpression, CqlAggregate aggregate)
: base(CqlEnumerableExpressionKind.Aggregate)
{
this.SourceExpression = sourceExpression ?? throw new ArgumentNullException(nameof(sourceExpression));
this.Aggregate = aggregate ?? throw new ArgumentNullException(nameof(aggregate));
}

public CqlEnumerableExpression SourceExpression { get; }

public CqlAggregate Aggregate { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Query.Core.ClientDistributionPlan.Cql
{
internal enum CqlAggregateKind
{
Builtin,
Tuple,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Query.Core.ClientDistributionPlan.Cql
{
internal enum CqlAggregateOperatorKind
{
All,
Any,
Array,
Count,
First,
Last,
Max,
Min,
Sum,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Query.Core.ClientDistributionPlan.Cql
{
using System;
using System.Collections.Generic;

internal class CqlArrayCreateScalarExpression : CqlScalarExpression
{
private const string Array = "Array";

public CqlArrayCreateScalarExpression(IReadOnlyList<CqlScalarExpression> items)
: base(CqlScalarExpressionKind.ArrayCreate)
{
this.ArrayKind = Array;
this.Items = items ?? throw new ArgumentNullException(nameof(items));
}

public string ArrayKind { get; }

public IReadOnlyList<CqlScalarExpression> Items { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Query.Core.ClientDistributionPlan.Cql
{
using System;

internal class CqlArrayIndexerScalarExpression : CqlScalarExpression
{
public CqlArrayIndexerScalarExpression(CqlScalarExpression expression, ulong index)
: base(CqlScalarExpressionKind.ArrayIndexer)
{
this.Expression = expression ?? throw new ArgumentNullException(nameof(expression));
this.Index = index;
}

public CqlScalarExpression Expression { get; }

public ulong Index { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Query.Core.ClientDistributionPlan.Cql
{
using System;
using System.Collections.Generic;

internal class CqlArrayLiteral : CqlLiteral
{
public CqlArrayLiteral(IReadOnlyList<CqlLiteral> items)
: base(CqlLiteralKind.Array)
{
this.Items = items ?? throw new ArgumentNullException(nameof(items));
}

public IReadOnlyList<CqlLiteral> Items { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Query.Core.ClientDistributionPlan.Cql
{
using System;

internal class CqlBinaryScalarExpression : CqlScalarExpression
{
public CqlBinaryScalarExpression(CqlBinaryScalarOperatorKind operatorKind, CqlScalarExpression leftExpression, CqlScalarExpression rightExpression)
: base(CqlScalarExpressionKind.BinaryOperator)
{
this.OperatorKind = operatorKind;
this.LeftExpression = leftExpression ?? throw new ArgumentNullException(nameof(leftExpression));
this.RightExpression = rightExpression ?? throw new ArgumentNullException(nameof(rightExpression));
}

public CqlBinaryScalarOperatorKind OperatorKind { get; }

public CqlScalarExpression LeftExpression { get; }

public CqlScalarExpression RightExpression { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Query.Core.ClientDistributionPlan.Cql
{
internal enum CqlBinaryScalarOperatorKind
{
Add,
And,
BitwiseAnd,
BitwiseOr,
BitwiseXor,
Divide,
Equal,
GreaterThan,
GreaterThanOrEqual,
LeftShift,
LessThan,
LessThanOrEqual,
Modulo,
Multiply,
NotEqual,
Or,
RightShift,
Subtract,
ZeroFillRightShift
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Query.Core.ClientDistributionPlan.Cql
{
internal class CqlBooleanLiteral : CqlLiteral
{
public CqlBooleanLiteral(bool value)
: base(CqlLiteralKind.Boolean)
{
this.Value = value;
}

public bool Value { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Query.Core.ClientDistributionPlan.Cql
{
internal class CqlBuiltinAggregate : CqlAggregate
{
public CqlBuiltinAggregate(CqlAggregateOperatorKind operatorKind)
: base(CqlAggregateKind.Builtin)
{
this.OperatorKind = operatorKind;
}

public CqlAggregateOperatorKind OperatorKind { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Query.Core.ClientDistributionPlan.Cql
{
internal enum CqlBuiltinScalarFunctionKind
{
Abs,
Acos,
All,
Any,
Array,
Array_Concat,
Array_Contains,
Array_Length,
Array_Slice,
Asin,
Atan,
Atn2,
Avg,
Ceiling,
Choose,
Concat,
Contains,
Cos,
Cot,
Count,
DateTimeAdd,
DateTimeBin,
DateTimeDiff,
DateTimeFromParts,
DateTimePart,
DateTimeToTicks,
DateTimeToTimestamp,
Degrees,
DocumentId,
EndsWith,
Exp,
First,
Floor,
GetCurrentDateTime,
GetCurrentDateTimeStatic,
GetCurrentTicks,
GetCurrentTicksStatic,
GetCurrentTimestamp,
GetCurrentTimestampStatic,
Iif,
Index_Of,
IntAdd,
IntBitAnd,
IntBitLeftShift,
IntBitNot,
IntBitOr,
IntBitRightShift,
IntBitXor,
IntDiv,
IntMod,
IntMul,
IntSub,
Is_Array,
Is_Bool,
Is_DateTime,
Is_Defined,
Is_Finite_Number,
Is_Integer,
Is_Null,
Is_Number,
Is_Object,
Is_Primitive,
Is_String,
Last,
LastIndexOf,
Left,
Length,
Like,
Log,
Log10,
Lower,
Ltrim,
Max,
Min,
NumberBin,
ObjectToArray,
Pi,
Power,
Radians,
Rand,
RegexMatch,
Replace,
Replicate,
Reverse,
Right,
Round,
Rtrim,
SetDifference,
SetIntersect,
SetUnion,
Sign,
Sin,
Sqrt,
Square,
ST_Area,
ST_Distance,
ST_Intersects,
ST_IsValid,
ST_IsValidDetailed,
ST_Within,
StartsWith,
StringEquals,
StringToArray,
StringToBoolean,
StringToNull,
StringToNumber,
StringToObject,
Substring,
Sum,
Tan,
TicksToDateTime,
TimestampToDateTime,
ToString,
Trim,
Trunc,
Upper
}
}
Loading

0 comments on commit 4556567

Please sign in to comment.