-
Notifications
You must be signed in to change notification settings - Fork 14
#640: Refactored generic tests for r #644
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
Open
sgn4sangar
wants to merge
14
commits into
master
Choose a base branch
from
refactor/640_generic_tests_r
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
cf3fcc1
refactored basic.py
sgn4sangar 948b895
Revert "refactored basic.py"
sgn4sangar 3980766
integrating test scripts for python3 with UDF scripts
sgn4sangar 75392f7
test the python3 folder
sgn4sangar 923b72d
cmd line wont pass lang, hence update udf.opts.lang
sgn4sangar 0fa2d3d
committing java codes
sgn4sangar 1d47dc7
updating the python3 files alone
sgn4sangar 6feedbc
fixed all python3 and java variants
sgn4sangar ca670fa
committing r files
sgn4sangar fdfe0af
committing r files with fixes
sgn4sangar 85580d1
extending ci.json
sgn4sangar 4c0ce79
deleting python3 and java for review purpose
sgn4sangar b682324
remove the generic python3 tests
sgn4sangar 350502e
removing the generic tests for all flavors
sgn4sangar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| from exasol_python_test_framework import udf | ||
| import pathlib | ||
| import re | ||
|
|
||
|
|
||
| class BasicTest(udf.TestCase): | ||
| def setUp(self): | ||
| self.query('DROP SCHEMA FN1 CASCADE', ignore_errors=True) | ||
| self.query('CREATE SCHEMA FN1') | ||
| self.query('OPEN SCHEMA FN1') | ||
|
|
||
| # Load R scripts from SQL files | ||
| lang_path = pathlib.Path(__file__).parent.parent.parent.parent / 'lang' / 'r' | ||
| for sql_filename in ['basic.sql', 'performance.sql']: | ||
| sql_file = lang_path / sql_filename | ||
| with open(sql_file, 'r') as f: | ||
| sql_content = f.read() | ||
|
|
||
| # Execute each CREATE SCRIPT statement | ||
| statements = re.split(r'^\s*/\s*$', sql_content, flags=re.MULTILINE) | ||
| for stmt in statements: | ||
| stmt = stmt.strip() | ||
| if stmt and 'CREATE' in stmt.upper(): | ||
| self.query(stmt) | ||
|
|
||
| def test_basic_scalar_emits(self): | ||
| rows = self.query(''' | ||
| SELECT fn1.basic_range(3) | ||
| FROM DUAL | ||
| ''') | ||
| self.assertRowsEqual([(x,) for x in range(3)], sorted(rows)) | ||
|
|
||
| def test_basic_set_returns(self): | ||
| rows = self.query(''' | ||
| SELECT fn1.basic_sum(3) | ||
| FROM DUAL | ||
| ''') | ||
| self.assertRowsEqual([(3,)], rows) | ||
|
|
||
| def test_emit_two_ints(self): | ||
| rows = self.query(''' | ||
| SELECT fn1.basic_emit_two_ints() | ||
| FROM DUAL''') | ||
| self.assertRowsEqual([(1, 2)], rows) | ||
|
|
||
| def test_simple_combination(self): | ||
| rows = self.query(''' | ||
| SELECT fn1.basic_sum(psum) | ||
| FROM ( | ||
| SELECT fn1.basic_nth_partial_sum(n) AS PSUM | ||
| FROM ( | ||
| SELECT fn1.basic_range(10) | ||
| FROM DUAL | ||
| ) | ||
| )''') | ||
| self.assertRowsEqual([(165,)], rows) | ||
|
|
||
| def test_simple_combination_grouping(self): | ||
| rows = self.query(''' | ||
| SELECT fn1.BASIC_SUM_GRP(psum) | ||
| FROM ( | ||
| SELECT MOD(N, 3) AS n, | ||
| fn1.basic_nth_partial_sum(n) AS psum | ||
| FROM ( | ||
| SELECT fn1.basic_range(10) | ||
| FROM DUAL | ||
| ) | ||
| ) | ||
| GROUP BY n | ||
| ORDER BY 1''') | ||
| self.assertRowsEqual([(39.0,), (54.0,), (72.0,)], rows) | ||
|
|
||
| def test_reset(self): | ||
| rows = self.query(''' | ||
| SELECT fn1.basic_test_reset(i, j) | ||
| FROM (SELECT fn1.basic_emit_several_groups(16, 8) FROM DUAL) | ||
| GROUP BY i | ||
| ORDER BY 1''') | ||
| self.assertRowsEqual([(0.0,), (0.0,), (0.0,), (0.0,), (1.0,), (1.0,), (1.0,), (1.0,), (2.0,)], rows[:9]) | ||
|
|
||
| def test_order_by_clause(self): | ||
| rows = self.query(''' | ||
| SELECT fn1.performance_reduce_characters(w, c) | ||
| FROM ( | ||
| SELECT fn1.performance_map_characters('hello hello hello abc') | ||
| FROM DUAL | ||
| ) | ||
| GROUP BY w | ||
| ORDER BY c DESC''') | ||
|
|
||
| unsorted_list = [tuple(x) for x in rows] | ||
| sorted_list = sorted(unsorted_list, key=lambda x: x[1], reverse=True) | ||
| #for x in zip(unsorted_list, sorted_list): | ||
| # print x | ||
|
|
||
| self.assertEqual(sorted_list, unsorted_list) | ||
|
|
||
|
|
||
| class SetWithEmptyInput(udf.TestCase): | ||
| def setUp(self): | ||
| self.query('DROP SCHEMA FN1 CASCADE', ignore_errors=True) | ||
| self.query('CREATE SCHEMA FN1') | ||
| self.query('OPEN SCHEMA FN1') | ||
|
|
||
| # Load R scripts from SQL file | ||
| sql_file = pathlib.Path(__file__).parent.parent.parent.parent / 'lang' / 'r' / 'basic.sql' | ||
| with open(sql_file, 'r') as f: | ||
| sql_content = f.read() | ||
|
|
||
| # Execute each CREATE SCRIPT statement | ||
| statements = re.split(r'^\s*/\s*$', sql_content, flags=re.MULTILINE) | ||
| for stmt in statements: | ||
| stmt = stmt.strip() | ||
| if stmt and 'CREATE' in stmt.upper(): | ||
| self.query(stmt) | ||
|
|
||
| self.query('DROP SCHEMA FN2 CASCADE', ignore_errors=True) | ||
| self.query('CREATE SCHEMA FN2') | ||
| self.query('CREATE TABLE FN2.empty_table(c int)') | ||
|
|
||
| def test_set_returns_has_empty_input_group_by(self): | ||
| self.query("""select FN1.set_returns_has_empty_input(c) from empty_table group by 'X'""") | ||
| self.assertEqual(0, self.rowcount()) | ||
|
|
||
| def test_set_returns_has_empty_input_no_group_by(self): | ||
| rows = self.query('''select FN1.set_returns_has_empty_input(c) from empty_table''') | ||
| self.assertRowsEqual([(None,)], rows) | ||
|
|
||
|
|
||
| def test_set_emits_has_empty_input_group_by(self): | ||
| self.query("""select FN1.set_emits_has_empty_input(c) from empty_table group by 'X'""") | ||
| self.assertEqual(0, self.rowcount()) | ||
|
|
||
| def test_set_emits_has_empty_input_no_group_by(self): | ||
| rows = self.query('''select FN1.set_emits_has_empty_input(c) from empty_table''') | ||
| self.assertRowsEqual([(None,None)], rows) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| udf.main() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this went completely wrong, we want the UDF definition in this file