You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2021/08/23 17:51:05 UTC

[GitHub] [superset] betodealmeida commented on a change in pull request #16357: feat: Add `long_table` example to big data script

betodealmeida commented on a change in pull request #16357:
URL: https://github.com/apache/superset/pull/16357#discussion_r694183967



##########
File path: superset/utils/mock_data.py
##########
@@ -68,7 +70,9 @@
 
 
 # pylint: disable=too-many-return-statements, too-many-branches
-def get_type_generator(sqltype: sqlalchemy.sql.sqltypes) -> Callable[[], Any]:
+def get_type_generator(
+    sqltype: sqlalchemy.sql.sqltypes, group_by: bool = False
+) -> Callable[[], Any]:

Review comment:
       @hugh can you give more details about why you need to pass `group_by` here? Can we achieve this some other way?
   
   A group by is not an intrinsic concept of a table, so passing it to a function that populates a table with random data is confusing.
   
   If you want the column name to have a single character and can't have that because of line 94 (`length = max(8, length)`), I think it's better to create your own type:
   
   ```python
   class SingleChar(sqlalchemy.sql.sqltypes.String):
       pass
   ```
   
   Then modify the function to check for your type before checking for `sqlalchemy.sql.sqltypes.String`:
   
   ```python
   if isinstance(sqltype, sqlalchemy.sql.sqltypes.String):
       return lambda: random.choice(string.ascii_letters)
   
   if isinstance(
           sqltype, (sqlalchemy.sql.sqltypes.VARCHAR, sqlalchemy.sql.sqltypes.String)
   ):
       ...
   ```
   
   Then define your columns:
   
   ```python
   from superset.utils.mock_data import SingleChar
   
   column = {
       "name": "groupable",
       "type": SingleChar(),
       "nullable": False,
       "default": None,
       "autoincrement": "auto",
       "primary_key": 0,
   }
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org