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

[Coral-Schema] Support ROW_NUMBER() OVER WINDOW #437

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,14 @@ public RexNode visitCall(RexCall rexCall) {

@Override
public RexNode visitOver(RexOver rexOver) {
// TODO: implement this method
return super.visitOver(rexOver);
/**
* For aggregates over window, derive the expected field's schema using RexOver's return type alone.
* Example RexOver:
* ROW_NUMBER() OVER (PARTITION BY colA, colB ORDER BY colC DESC)
*/
appendField(rexOver.getType(), false,
ljfgem marked this conversation as resolved.
Show resolved Hide resolved
SchemaUtilities.generateDocumentationForFunctionCall(rexOver, inputSchema, inputNode));
return rexOver;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,19 @@ public void testProjectUdfReturnedStruct() {
TestUtils.loadSchema("testProjectUdfReturnedStruct-expected.avsc"));
}

@Test
public void testRowNumberOverWindow() {
String viewSql = "CREATE VIEW foo_with_rownumber_over_window AS SELECT *, ROW_NUMBER() OVER"
+ " (PARTITION BY Id, Struct_Col.Bigint_Field" + " ORDER BY Id DESC) rank" + " FROM basecomplex bc";

TestUtils.executeCreateViewQuery("default", "foo_with_rownumber_over_window", viewSql);

ViewToAvroSchemaConverter viewToAvroSchemaConverter = ViewToAvroSchemaConverter.create(hiveMetastoreClient);
Schema actualSchema = viewToAvroSchemaConverter.toAvroSchema("default", "foo_with_rownumber_over_window");

Assert.assertEquals(actualSchema.toString(true), TestUtils.loadSchema("testRowNumberOverWindow-expected.avsc"));
}

@Test
public void testLowercaseSchema() {
String viewSql = "CREATE VIEW v AS SELECT id as Id FROM basecomplex";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"type" : "record",
"name" : "foo_with_rownumber_over_window",
"namespace" : "default.foo_with_rownumber_over_window",
"fields" : [ {
"name" : "Id",
"type" : "int"
}, {
"name" : "Array_Col",
"type" : [ "null", {
"type" : "array",
"items" : [ "null", "string" ]
} ]
}, {
"name" : "Map_Col",
"type" : [ "null", {
"type" : "map",
"values" : [ "null", "string" ]
} ]
}, {
"name" : "Struct_Col",
"type" : [ "null", {
"type" : "record",
"name" : "Struct_col",
"namespace" : "default.foo_with_rownumber_over_window.foo_with_rownumber_over_window",
"fields" : [ {
"name" : "Bool_Field",
"type" : "boolean"
}, {
"name" : "Int_Field",
"type" : [ "null", "int" ]
}, {
"name" : "Bigint_Field",
"type" : "long"
}, {
"name" : "Float_Field",
"type" : [ "null", "float" ]
}, {
"name" : "Double_Field",
"type" : "double"
}, {
"name" : "Date_String_Field",
"type" : [ "null", "string" ]
}, {
"name" : "String_Field",
"type" : [ "null", "string" ]
} ]
} ]
}, {
"name" : "rank",
"type" : "long",
"doc" : "Field created in view by applying operator 'ROW_NUMBER'"
} ]
}
Loading