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

[bugfix/max_and_min_string] #2814

Merged
merged 1 commit into from
Jan 3, 2024

Conversation

tt88dev
Copy link
Contributor

@tt88dev tt88dev commented Jan 2, 2024

Bugfix feature - String columns to support MAX and MIN

We have the following table:

class example extends Table {
  IntColumn get id => integer().autoIncrement()();
  TextColumn get name => text()();
  TextColumn get string_type => text().withDefault(const Constant('N'))(); //N,Y
  RealColumn get quantity => real()();
}

Example Table:

id name string_type quantity
1 TREE01 N 700.0
2 TREE01 N 800.0
3 TREE01 N 600.0
4 TREE01 Y 200.0

We need to execute the following SQL:

SELECT
	"example"."name" AS "example.name",
	MAX("example"."string_type") AS "c1",
	SUM("example"."quantity") AS "c2"
FROM
	"example"
GROUP BY
	"example"."name"

Result:

example.name c1 c2
TREE01 Y 2300.0

The following is how to use it.

    final maxStringType = example.string_type.max(); //<-- Fix this LINE
    final sumQuantity = example.quantity.sum();
    final queryExample = selectOnly(
      example,
    )
      ..addColumns([
        example.name,
        maxStringType,
        sumQuantity,
      ])
      ..groupBy([
        example.name,
      ])
     ;

@tt88dev tt88dev force-pushed the bugfix/max-and-min-string branch 3 times, most recently from d0de4d1 to 013a39a Compare January 2, 2024 10:26
Copy link
Owner

@simolus3 simolus3 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

Could you add a test for this as well? test/database/expressions/aggregate_test.dart has the others, you can test this for strings in a similar way by creating a CustomExpression<String>

@tt88dev
Copy link
Contributor Author

tt88dev commented Jan 3, 2024

Thanks for the contribution!

Could you add a test for this as well? test/database/expressions/aggregate_test.dart has the others, you can test this for strings in a similar way by creating a CustomExpression<String>

Certainly! I've already added a test for that along with the recent changes.

@tt88dev
Copy link
Contributor Author

tt88dev commented Jan 3, 2024

Thanks for the contribution!
Could you add a test for this as well? test/database/expressions/aggregate_test.dart has the others, you can test this for strings in a similar way by creating a CustomExpression<String>

Certainly! I've already added a test for that along with the recent changes.

In addition, I have just helped to complete more other tests, in another Issue, please refer to #2819

Copy link
Owner

@simolus3 simolus3 left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

@simolus3 simolus3 merged commit 379b92d into simolus3:develop Jan 3, 2024
10 checks passed
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.

None yet

2 participants