Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Date range filter #12

Merged
merged 9 commits into from
Mar 5, 2020
Merged

Support Date range filter #12

merged 9 commits into from
Mar 5, 2020

Conversation

itye-msft
Copy link
Member

Added support for date range filter

@itye-msft itye-msft requested a review from a team as a code owner February 26, 2020 15:56
@@ -29,8 +30,19 @@ public void Visit(RangeClause rangeClause)
{
// general "is between" filter on numeric fields uses a rangeClause query with GTE+LT (not LTE like above)
EnsureClause.IsNotNull(rangeClause.LTValue, nameof(rangeClause.LTValue));

rangeClause.KustoQL = $"{rangeClause.FieldName} >= {rangeClause.GTEValue} and {rangeClause.FieldName} < {rangeClause.LTValue}";
var t = ClauseFieldTypeProcessor.GetType(schemaRetriever, rangeClause.FieldName).Result;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be awaited?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it should. How about I open a new issue to change this as a new user story?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#22

[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "Resources are not supported yet.")]
public static async Task<ClauseFieldType> GetType(ISchemaRetriever schemaRetriever, string fieldName)
{
if (schemaRetriever == null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensure can be used?

K2Bridge.Tests.UnitTests/K2Bridge.Tests.UnitTests.csproj Outdated Show resolved Hide resolved
Comment on lines 37 to 39
case ClauseFieldType.Text:
rangeClause.KustoQL = $"{rangeClause.FieldName} >= {rangeClause.GTEValue} and {rangeClause.FieldName} < {rangeClause.LTValue}";
break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Range clause can't work with text types in ADX. this case should throw an error.
  2. Something is wrong in the tests since a query like: field >= aaa and field < bbb should fail since you're missing quotes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -76,7 +78,7 @@ public string Visit_WithValidTermQuery_ReturnsValidReponse()
var es = phraseQuery.ESQuery;
Assert.NotNull(es);

var visitor = new ElasticSearchDSLVisitor(SchemaRetrieverMock.CreateMockSchemaRetriever());
var visitor = VisitorTestsUtils.CreateRootVisitor();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A) here you are using the utils class

@@ -57,7 +59,8 @@ public string Visit_WithValidRangeQuery_ReturnsValidResponse()
var es = rangeQuery.ESQuery;
Assert.NotNull(es);

var visitor = new ElasticSearchDSLVisitor(SchemaRetrieverMock.CreateMockSchemaRetriever());
var visitor = new ElasticSearchDSLVisitor(SchemaRetrieverMock.CreateMockSchemaRetriever("days", "long"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

b) Here you are using the new ESDSLvisitor statement.

/// Have the ISchemaRetriever initialised by the default visitor.
/// </summary>
/// <param name="visitor"></param>
internal static void AddRootDsl(ElasticSearchDSLVisitor visitor)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name is not so clear.
e.g.
WrapWithRootDslAndAccept (maybe too long)
AddRootAndAccept?
AcceptWithRoot?

but AddRootDsl which gets a visitor. seems like the visitor is the one being added to (or added into) with the root....

},
IndexName = "someindex",
};
visitor.Visit(dsl);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, the method says: AddRootDsl
but at the end you call visit... so its much more that just add root. it actually visits.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, I think you shouldnt use visitor.Visit but dsl.Accept(visitor)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed the method, however, I kept Visit since I am not changing existing tests code.

{
var visitor = new ElasticSearchDSLVisitor(SchemaRetrieverMock.CreateMockSchemaRetriever());
AddRootDsl(visitor);
return visitor;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you have an issue. you 'AddRootDsl' which already visits and then you return a visitor. needs some refactoring to be clearer

_ => false,
};
Ensure.IsNotNullOrEmpty(fieldName, nameof(fieldName));
var t = await ClauseFieldTypeProcessor.GetType(schemaRetriever, fieldName);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var t = await ClauseFieldTypeProcessor.GetType(schemaRetriever, fieldName);
var fieldType = await ClauseFieldTypeProcessor.GetType(schemaRetriever, fieldName);

Copy link
Collaborator

@eladiw eladiw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the right direction, however I think there is some mixup in the addRootDsl method

@@ -379,15 +380,15 @@ public string TestComplexWildcardQuery(string queryString)
public string TestPrefixQuery(string queryString)
{
var query = JsonConvert.DeserializeObject<Query>(queryString);
var visitor = new ElasticSearchDSLVisitor(SchemaRetrieverMock.CreateMockSchemaRetriever());
var visitor = VisitorTestsUtils.CreateAndVisitRootVisitor();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of those tests (like this) are now visited twice? was once before...

@eladiw eladiw merged commit 1ed785f into master Mar 5, 2020
@eladiw eladiw deleted the feature/AddTimeRangeQuery branch March 5, 2020 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants