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

Add aggregate function count_if for relational table #14511

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yx-zhang
Copy link
Contributor

Add aggregate function count_if for relational table

Content1 ...

Content2 ...

Content3 ...


This PR has:

  • been self-reviewed.
    • concurrent read
    • concurrent write
    • concurrent read and write
  • added documentation for new or modified features or behaviors.
  • added Javadocs for most classes and all non-trivial methods.
  • added or updated version, license, or notice information
  • added comments explaining the "why" and the intent of the code wherever would not be obvious
    for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold
    for code coverage.
  • added integration tests.
  • been tested in a test IoTDB cluster.

Key changed/added classes (or packages if there are too many classes) in this PR

@@ -567,6 +567,7 @@ && isIntegerNumber(argumentTypes.get(2)))) {
case SqlConstant.MIN:
case SqlConstant.MAX:
case SqlConstant.MODE:
case SqlConstant.COUNT_IF:
Copy link
Contributor

Choose a reason for hiding this comment

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

the type of argument should be boolean?

@Override
public void addInput(int[] groupIds, Column[] arguments) {
for (int i = 0; i < groupIds.length; i++) {
if (arguments[0].getBoolean(i)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

firstly should check the nullability of arguments by if (arguments[0].isNull(i))

@Override
public void addInput(int[] groupIds, Column[] arguments) {
for (int i = 0; i < groupIds.length; i++) {
if (arguments[0].getBoolean(i)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (arguments[0].getBoolean(i)) {
if (!arguments[0].isNull(i) && arguments[0].getBoolean(i)) {

}

@Override
public void addStatistics(Statistics[] statistics) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

better to throw unsupported exception if we don't plan to support push down count_if into scan


private long countState = 0;

public CountIfAccumulator(List<TSDataType> seriesDataType) {
Copy link
Contributor

Choose a reason for hiding this comment

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

don't need to pass seriesDataType here, you should check data type in the analyze phase.

public void addInput(Column[] arguments) {
int count = arguments[0].getPositionCount();
for (int i = 0; i < count; i++) {
if (arguments[0].getBoolean(i)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (arguments[0].getBoolean(i)) {
if (!arguments[0].isNull(i) && arguments[0].getBoolean(i)) {

@Override
public void removeInput(Column[] arguments) {
for (int i = 0; i < arguments[0].getPositionCount(); i++) {
if (arguments[0].getBoolean(i)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (arguments[0].getBoolean(i)) {
if (!arguments[0].isNull(i) && arguments[0].getBoolean(i)) {

}

@Override
public void removeInput(Column[] arguments) {
Copy link
Contributor

Choose a reason for hiding this comment

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

you should also override removable method to return true.

@@ -149,6 +150,8 @@ private static GroupedAccumulator createBuiltinGroupedAccumulator(
switch (aggregationType) {
case COUNT:
return new GroupedCountAccumulator();
case COUNT_IF:
return new GroupedCountIfAccumulator(inputDataTypes);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return new GroupedCountIfAccumulator(inputDataTypes);
return new GroupedCountIfAccumulator();

@@ -433,6 +433,327 @@ public void countTest() {
tableResultSetEqualTest("select count(*) from table1", expectedHeader, retArray, DATABASE_NAME);
}

@Test
public void countIfTest() {
Copy link
Contributor

Choose a reason for hiding this comment

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

also need to add some extra unexpected exception test, like:

  1. input expression is not boolean type
  2. number of input expressions are not only 1

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.

2 participants