1717 OPTION_RANDOM , OPTION_RANDOM_SEED , OPTION_RANDOM_SEED_METHOD
1818
1919from .utils import ensure , topologicalSort , DataGenError , deprecated , split_list_matching_condition
20+ from .html_utils import HtmlUtils
2021from . _version import _get_spark_version
2122from .schema_parser import SchemaParser
2223
@@ -1187,13 +1188,14 @@ def _mkInsertOrUpdateStatement(self, columns, srcAlias, substitutions, isUpdate=
11871188
11881189 return ", " .join (results )
11891190
1190- def scriptTable (self , name = None , location = None , tableFormat = "delta" ):
1191+ def scriptTable (self , name = None , location = None , tableFormat = "delta" , asHtml = False ):
11911192 """ generate create table script suitable for format of test data set
11921193
11931194 :param name: name of table to use in generated script
11941195 :param location: path to location of data. If specified (default is None), will generate
11951196 an external table definition.
11961197 :param tableFormat: table format for table
1198+ :param asHtml: if true, generate output suitable for use with `displayHTML` method in notebook environment
11971199 :returns: SQL string for scripted table
11981200 """
11991201 assert name is not None , "`name` must be specified"
@@ -1219,14 +1221,21 @@ def scriptTable(self, name=None, location=None, tableFormat="delta"):
12191221 if location is not None :
12201222 results .append (f"location '{ location } '" )
12211223
1222- return "\n " .join (results )
1224+ results = "\n " .join (results )
1225+
1226+ if asHtml :
1227+ results = HtmlUtils .formatCodeAsHtml (results )
1228+
1229+ return results
12231230
12241231 def scriptMerge (self , tgtName = None , srcName = None , updateExpr = None , delExpr = None , joinExpr = None , timeExpr = None ,
12251232 insertExpr = None ,
12261233 useExplicitNames = True ,
12271234 updateColumns = None , updateColumnExprs = None ,
12281235 insertColumns = None , insertColumnExprs = None ,
1229- srcAlias = "src" , tgtAlias = "tgt" ):
1236+ srcAlias = "src" , tgtAlias = "tgt" ,
1237+ asHtml = False
1238+ ):
12301239 """ generate merge table script suitable for format of test data set
12311240
12321241 :param tgtName: name of target table to use in generated script
@@ -1253,6 +1262,7 @@ def scriptMerge(self, tgtName=None, srcName=None, updateExpr=None, delExpr=None,
12531262 By default, will use src column as update value for
12541263 target table. This should have the form [ ("update_column_name", "update column expr"), ...]
12551264 :param useExplicitNames: If True, generate explicit column names in insert and update statements
1265+ :param asHtml: if true, generate output suitable for use with `displayHTML` method in notebook environment
12561266 :returns: SQL string for scripted merge statement
12571267 """
12581268 assert tgtName is not None , "you must specify a target table"
@@ -1327,4 +1337,9 @@ def scriptMerge(self, tgtName=None, srcName=None, updateExpr=None, delExpr=None,
13271337
13281338 results .append (ins_clause )
13291339
1330- return "\n " .join (results )
1340+ result = "\n " .join (results )
1341+
1342+ if asHtml :
1343+ result = HtmlUtils .formatCodeAsHtml (results )
1344+
1345+ return result
0 commit comments