From ace38489897f41a069af412aa48a19d6e53d21b8 Mon Sep 17 00:00:00 2001 From: kennethmhc Date: Mon, 18 Jul 2022 19:16:10 +0800 Subject: [PATCH] [HOPSWORKS-3141] Fix query filter date type (#1007) --- .../src/test/ruby/spec/featureview_query.rb | 60 ++++++++++++++++++- hopsworks-api/pom.xml | 4 +- hopsworks-persistence/pom.xml | 4 +- pom.xml | 14 ++--- 4 files changed, 68 insertions(+), 14 deletions(-) diff --git a/hopsworks-IT/src/test/ruby/spec/featureview_query.rb b/hopsworks-IT/src/test/ruby/spec/featureview_query.rb index 89ae047159..a7c5277a9e 100644 --- a/hopsworks-IT/src/test/ruby/spec/featureview_query.rb +++ b/hopsworks-IT/src/test/ruby/spec/featureview_query.rb @@ -28,7 +28,6 @@ featurestore_id = get_featurestore_id(@project.id) featurestore_name = get_featurestore_name(@project.id) featuregroup_suffix = short_random_id - project_name = @project.projectname.downcase query = make_sample_query(@project, featurestore_id, featuregroup_suffix: featuregroup_suffix) json_result = create_feature_view(@project.id, featurestore_id, query) parsed_json = JSON.parse(json_result) @@ -64,7 +63,6 @@ it "should be able to retrieve original query" do featurestore_id = get_featurestore_id(@project.id) featurestore_name = get_featurestore_name(@project.id) - project_name = @project.projectname.downcase featuregroup_suffix = short_random_id query = make_sample_query(@project, featurestore_id, featuregroup_suffix: featuregroup_suffix) json_result = create_feature_view(@project.id, featurestore_id, query) @@ -91,7 +89,6 @@ it "should be able to create batch query using retrieved query" do featurestore_id = get_featurestore_id(@project.id) featurestore_name = get_featurestore_name(@project.id) - project_name = @project.projectname.downcase featuregroup_suffix = short_random_id query = make_sample_query(@project, featurestore_id, featuregroup_suffix: featuregroup_suffix) json_result = create_feature_view(@project.id, featurestore_id, query) @@ -132,6 +129,63 @@ expect(parsed_query_result["filter"]["rightLogic"]["leftFilter"]["condition"]).to eql("LESS_THAN_OR_EQUAL") expect(parsed_query_result["filter"]["rightLogic"]["leftFilter"]["value"]).to eql("4321") end + + + it "should be able to create sql string with different type of event time filter" do + featurestore_id = get_featurestore_id(@project.id) + project_name = @project.projectname.downcase + featurestore_name = get_featurestore_name(@project.id) + featuregroup_suffix = short_random_id + features_a = [ + { type: "INT", name: "id", primary: true }, + { type: "DATE", name: "ts_date" }, + { type: "TIMESTAMP", name: "ts" }, + ] + fg_id = create_cached_featuregroup_checked(@project.id, featurestore_id, "test_fg_a#{featuregroup_suffix}", + features: features_a, + event_time: "ts") + query = { + leftFeatureGroup: { + id: fg_id + }, + leftFeatures: [{ name: 'ts_date' }, { name: 'ts' }], + filter: { + type: "AND", + leftFilter: { + feature: { + name: "ts_date", + featureGroupId: fg_id + }, + condition: "GREATER_THAN", + value: "2022-01-01" + }, + rightFilter: { + feature: { + name: "ts", + featureGroupId: fg_id + }, + condition: "GREATER_THAN", + value: "2022-02-01 00:00:00" + } + } + } + + query_result = put "#{ENV['HOPSWORKS_API']}/project/#{@project.id}/featurestores/query", query.to_json + expect_status_details(200) + parsed_query_result = JSON.parse(query_result) + + expect(parsed_query_result['query']).to eql( + "SELECT `fg0`.`ts_date` `ts_date`, `fg0`.`ts` `ts`\n" + + "FROM `#{featurestore_name}`.`test_fg_a#{featuregroup_suffix}_1` `fg0`\n" + + "WHERE `fg0`.`ts_date` > DATE '#{query[:filter][:leftFilter][:value]}' AND `fg0`.`ts` > TIMESTAMP '#{query[:filter][:rightFilter][:value]}.000'" + ) + + expect(parsed_query_result['queryOnline']).to eql( + "SELECT `fg0`.`ts_date` `ts_date`, `fg0`.`ts` `ts`\n" + + "FROM `#{project_name.downcase}`.`test_fg_a#{featuregroup_suffix}_1` `fg0`\n" + + "WHERE `fg0`.`ts_date` > DATE '#{query[:filter][:leftFilter][:value]}' AND `fg0`.`ts` > TIMESTAMP '#{query[:filter][:rightFilter][:value]}.000'" + ) + end end end end diff --git a/hopsworks-api/pom.xml b/hopsworks-api/pom.xml index f810732d9b..b196813022 100644 --- a/hopsworks-api/pom.xml +++ b/hopsworks-api/pom.xml @@ -173,8 +173,8 @@ junit - org.apache.calcite - calcite-core + io.hops.calcite + calcite-core-shaded-guava-31 4.10.14 2.2 - 21.0 + 19.0 3.0.0 1.1.1 2.1.8 @@ -673,8 +673,8 @@ ${avro.version} - org.apache.calcite - calcite-core + io.hops.calcite + calcite-core-shaded-guava-31 ${calcite-core.version} @@ -688,8 +688,8 @@ - org.apache.calcite - calcite-server + io.hops.calcite + calcite-server-shaded-guava-31 ${calcite-server.version}