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 topK using the DBSP operator #954

Merged
merged 6 commits into from
Oct 30, 2023
Merged

Support topK using the DBSP operator #954

merged 6 commits into from
Oct 30, 2023

Conversation

mihaibudiu
Copy link
Collaborator

Is this a user-visible change (yes/no): no

Signed-off-by: Mihai Budiu <mbudiu@gmail.com>
@mihaibudiu
Copy link
Collaborator Author

I will work on a commit to add more tests.

* Apply a topK operation to each of the groups in an indexed collection.
* This always sorts the elements of each group.
* To sort the entire collection just group by ().
* The function is a DBSPSortExpression used to compare two elements.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is wrong, I will fix the comment in the next commit

@mihaibudiu
Copy link
Collaborator Author

mihaibudiu commented Oct 28, 2023

Here is a sample output produced:

        struct Cmpstream25;
        impl CmpFunc<Tuple6<i32, F64, bool, String, Option<i32>, Option<F64>>> for Cmpstream25 {
            fn cmp(left: &Tuple6<i32, F64, bool, String, Option<i32>, Option<F64>>, right: &Tuple6<i32, F64, bool, String, Option<i32>, Option<F64>>) -> std::cmp::Ordering {
                let ord = left.1.cmp(&right.1);
                if ord != Ordering::Equal { return ord; };
                let ord = left.0.cmp(&right.0);
                if ord != Ordering::Equal { return ord; };
                let ord = left.2.cmp(&right.2);
                if ord != Ordering::Equal { return ord; };
                let ord = left.3.cmp(&right.3);
                if ord != Ordering::Equal { return ord; };
                let ord = left.4.cmp(&right.4);
                if ord != Ordering::Equal { return ord; };
                let ord = left.5.cmp(&right.5);
                if ord != Ordering::Equal { return ord; };
                return Ordering::Equal;
            }
        }
        // DBSPIndexedTopKOperator 556
        let stream25: Stream<_, OrdIndexedZSet<(), Tuple6<i32, F64, bool, String, Option<i32>, Option<F64>>, Weight>> = stream23.topk_custom_order::<Cmpstream25>(cast_to_u_i32(1i32));

this.circuit.addOperator(integral);
index = integral;
}
// Global sort. Implemented by aggregate in a single Vec<> which is then sorted.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this code is unchanged

@ryzhyk
Copy link
Contributor

ryzhyk commented Oct 28, 2023

Here is a sample output produced:

        struct Cmpstream25;
        impl CmpFunc<Tuple6<i32, F64, bool, String, Option<i32>, Option<F64>>> for Cmpstream25 {
            fn cmp(left: &Tuple6<i32, F64, bool, String, Option<i32>, Option<F64>>, right: &Tuple6<i32, F64, bool, String, Option<i32>, Option<F64>>) -> std::cmp::Ordering {
                let ord = left.1.cmp(&right.1);
                if ord != Ordering::Equal { return ord; };
                let ord = left.0.cmp(&right.0);
                if ord != Ordering::Equal { return ord; };
                let ord = left.2.cmp(&right.2);
                if ord != Ordering::Equal { return ord; };
                let ord = left.3.cmp(&right.3);
                if ord != Ordering::Equal { return ord; };
                let ord = left.4.cmp(&right.4);
                if ord != Ordering::Equal { return ord; };
                let ord = left.5.cmp(&right.5);
                if ord != Ordering::Equal { return ord; };
                return Ordering::Equal;
            }
        }
        // DBSPIndexedTopKOperator 556
        let stream25: Stream<_, OrdIndexedZSet<(), Tuple6<i32, F64, bool, String, Option<i32>, Option<F64>>, Weight>> = stream23.topk_custom_order::<Cmpstream25>(cast_to_u_i32(1i32));

Looks good, assuming it's all order by .. ASC in SQL.

@mihaibudiu
Copy link
Collaborator Author

Right, have to handle descending. Easy.

@ryzhyk
Copy link
Contributor

ryzhyk commented Oct 28, 2023

BTW, I think this is a user-visible change, which requires docs + a changelog entry.

@mihaibudiu
Copy link
Collaborator Author

which part is visible? LIMIT was there in the grammar.

@ryzhyk
Copy link
Contributor

ryzhyk commented Oct 28, 2023

which part is visible? LIMIT was there in the grammar.

Clearly, we're adding a new user-visible capability.

@mihaibudiu
Copy link
Collaborator Author

No, we are fixing a bug

@ryzhyk
Copy link
Contributor

ryzhyk commented Oct 28, 2023

No, we are fixing a bug

So you're saying we're implementing a behavior that documentation already promised before. If the documentation is accurate, then we're good. A changelog entry documenting the bug fix is still in order.

Signed-off-by: Mihai Budiu <mbudiu@gmail.com>
import java.util.List;
import java.util.Set;

import static org.dbsp.sqlCompiler.ir.type.DBSPTypeCode.USER;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This code was moved here from DBSPExecutor

Signed-off-by: Mihai Budiu <mbudiu@gmail.com>
Signed-off-by: Mihai Budiu <mbudiu@gmail.com>
Signed-off-by: Mihai Budiu <mbudiu@gmail.com>
Signed-off-by: Mihai Budiu <mbudiu@gmail.com>
@mihaibudiu mihaibudiu merged commit 8c00856 into main Oct 30, 2023
5 checks passed
@mihaibudiu mihaibudiu deleted the topk branch October 30, 2023 15:52
@ryzhyk ryzhyk added the SQL compiler Related to the SQL compiler label Oct 30, 2023
@ryzhyk ryzhyk added this to the November 07, 2023 milestone Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SQL compiler Related to the SQL compiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants