Conversation
…nt and batch inserts
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refines the test suite's data generation capabilities by introducing a configurable row count for random database creation and optimizing data insertion through batching. These improvements enhance the efficiency and adaptability of test data setup for a wide range of test scenarios. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request enhances the test data generation by making the number of random rows configurable in dropandcreateDB_random and by introducing batch inserts for better performance. The changes are applied across numerous test files. While the batch insertion is a good improvement, the implementation in test_nestedQuery.py contains significant code duplication that should be refactored for better maintainability. My review includes a suggestion to address this.
| # stable_1_1 values | ||
| values_stable_1_1.append('''(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', | ||
| 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s')''' | ||
| % (ts + i*1000, fake.random_int(min=-2147483647, max=2147483647, step=1), | ||
| fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), | ||
| fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , | ||
| fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , | ||
| fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) | ||
| tdSql.execute('''insert into regular_table_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ | ||
| q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ | ||
| values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ | ||
| 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' | ||
| # regular_table_1 values | ||
| values_regular_table_1.append('''(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', | ||
| 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s')''' | ||
| % (ts + i*1000, fake.random_int(min=-2147483647, max=2147483647, step=1) , | ||
| fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1) , | ||
| fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , | ||
| fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , | ||
| fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) |
There was a problem hiding this comment.
The logic to generate values for stable_1_1 and regular_table_1 is identical, leading to code duplication. You can generate the value string once and append it to both lists.
This pattern of duplication also appears for other tables (stable_1_2 vs regular_table_2, and within stable_2_1 variants) and in the final block of tdSql.execute calls. Consider refactoring the entire data generation and insertion logic to be more modular, for example by using helper functions. This will improve readability and maintainability.
| # stable_1_1 values | |
| values_stable_1_1.append('''(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', | |
| 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s')''' | |
| % (ts + i*1000, fake.random_int(min=-2147483647, max=2147483647, step=1), | |
| fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), | |
| fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , | |
| fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , | |
| fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) | |
| tdSql.execute('''insert into regular_table_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ | |
| q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ | |
| values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ | |
| 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' | |
| # regular_table_1 values | |
| values_regular_table_1.append('''(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', | |
| 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s')''' | |
| % (ts + i*1000, fake.random_int(min=-2147483647, max=2147483647, step=1) , | |
| fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1) , | |
| fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , | |
| fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , | |
| fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) | |
| # stable_1_1 and regular_table_1 values | |
| row_values = '''(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', | |
| 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s')''' % (ts + i*1000, fake.random_int(min=-2147483647, max=2147483647, step=1) , | |
| fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1) , | |
| fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , | |
| fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , | |
| fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr()) | |
| values_stable_1_1.append(row_values) | |
| values_regular_table_1.append(row_values) |
There was a problem hiding this comment.
Pull request overview
This PR standardizes/extends several test helpers that create random databases by adding a num_random parameter (to control generated table/row volume), updates many tests to call these helpers with num_random=50, and refactors one nested-query data generator to use batched inserts for better performance.
Changes:
- Add
num_randomparameter to multipledropandcreateDB_random()helpers and update callers to passnum_random=50. - Implement batched insert generation in
test/cases/09-DataQuerying/08-SubQuery/test_nestedQuery.pyto reduce per-row execute overhead. - Adjust a handful of existing test cases to use the new helper signature.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| test/cases/uncatalog/system-test/2-query/test_para_tms2.py | Adds num_random to DB generator and updates calls to generate fewer rows. |
| test/cases/uncatalog/system-test/2-query/test_para_tms.py | Adds num_random to DB generator and updates call sites (including commented examples). |
| test/cases/uncatalog/system-test/2-query/test_nestedQuery.py | Adds num_random and updates call sites to generate fewer rows. |
| test/cases/uncatalog/system-test/2-query/test_max_min_data.py | Adds num_random and updates calls (but currently conflicts with hard-coded expectations). |
| test/cases/14-JoinQueries/test_join_func_cursor.py | Adds num_random and updates call sites to generate fewer rows. |
| test/cases/14-JoinQueries/test_join_func.py | Adds num_random and updates call sites to generate fewer rows. |
| test/cases/11-Functions/03-Selection/test_select_last_model.py | Updates NestedQueryHelper.dropandcreateDB_random() call to pass num_random=50. |
| test/cases/11-Functions/02-Aggregate/test_agg_bugs.py | Adds num_random and updates call site to use num_random=50. |
| test/cases/09-DataQuerying/18-Stability/test_query_stability26.py | Updates helper call to pass num_random=50. |
| test/cases/09-DataQuerying/18-Stability/test_query_stability.py | Adds num_random and updates call sites to pass num_random=50. |
| test/cases/09-DataQuerying/13-CaseWhen/test_query_case_when.py | Adds num_random and updates call to pass num_random explicitly. |
| test/cases/09-DataQuerying/08-SubQuery/test_nestedQuery_time.py | Adds num_random and updates call sites to pass num_random=50. |
| test/cases/09-DataQuerying/08-SubQuery/test_nestedQuery.py | Adds num_random, switches inserts to batching, and updates call sites to pass num_random=50. |
| test/cases/09-DataQuerying/03-GroupBy/test_query_groupby_noreturn.py | Updates helper call to pass num_random=50. |
| test/cases/09-DataQuerying/03-GroupBy/test_query_groupby_alwaysreturn.py | Updates helper call to pass num_random=50. |
| test/cases/06-DataIngestion/01-SQL/test_write_null_none.py | Adds num_random and updates call to pass num_random explicitly. |
| test/cases/06-DataIngestion/01-SQL/test_write_basic.py | Adds num_random parameter and updates a call site (but helper does not currently use num_random). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| % (ts + i*1000*60*60*4 +1, fake.random_int(min=-0, max=2147483647, step=1), | ||
| fake.random_int(min=-0, max=9223372036854775807, step=1), | ||
| fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) , |
| % (ts + i*1000*60*60*4 +10, fake.random_int(min=-0, max=2147483647, step=1), | ||
| fake.random_int(min=-0, max=9223372036854775807, step=1), | ||
| fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) , |
| # ------------------ test_system_insert_select.py ------------------ | ||
| # | ||
| def dropandcreateDB_random(self,database,n): | ||
| def dropandcreateDB_random(self,database,n,num_random=100): |
| startTime = time.time() | ||
| os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) | ||
| self.dropandcreateDB_random("%s" %self.db, random.randint(10000,30000)) | ||
| self.dropandcreateDB_random("%s" %self.db, random.randint(10000,30000), num_random=50) |
| os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) | ||
|
|
||
| self.dropandcreateDB_random("%s" %self.db, 2000) | ||
| self.dropandcreateDB_random("%s" %self.db, 2000, num_random=50) |
| self.TD_22219_max("%s" %self.db) | ||
|
|
||
| self.dropandcreateDB_random("%s" %self.db, 2000) | ||
| self.dropandcreateDB_random("%s" %self.db, 2000, num_random=50) |
| % (ts + i*1000*60*60*4, fake.random_int(min=-0, max=2147483647, step=1), | ||
| fake.random_int(min=-0, max=9223372036854775807, step=1), | ||
| fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) , |
No description provided.