<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Load data from Semantic Model to Lakehouse where semantic model column names start with Capitals in Data Science</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Science/Load-data-from-Semantic-Model-to-Lakehouse-where-semantic-model/m-p/4103951#M265</link>
    <description>&lt;P&gt;Hi there - trying to lload a tabe from a semantic model to a lakehouse but the issue is that the table in the semantic model I want to load from has column names that start with Capital letters (for ease of use).&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Obviously this breaks the rules of lakehouse tables&amp;nbsp; - how do i fix this - ideally dynamically ?&lt;BR /&gt;&lt;BR /&gt;Code below&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;EM&gt;import sempy.fabric as fabric&lt;/EM&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;EM&gt;#Dev&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;#workspace_ID = "XXXXXX"&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;#Stage&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;#workspace_ID = "XXXXXX"&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;#Prod&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;workspace_ID = "XXXXXX"&lt;/EM&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;EM&gt;workspace_Safe_ID = workspace_ID.replace("-","_")&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;df_table = fabric.read_table("PSG_CTD_GDS_OMNI_Production", "_Environments",workspace=workspace_ID)&lt;/EM&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;EM&gt;df_table.to_lakehouse_table("Environments", "overwrite")&lt;BR /&gt;&lt;BR /&gt;&lt;/EM&gt;And error log&amp;nbsp;&lt;BR /&gt;&lt;P&gt;Cell In[8], line 13&lt;BR /&gt;10 workspace_Safe_ID = workspace_ID.replace("-","_")&lt;BR /&gt;11 df_table = fabric.read_table("PSG_CTD_GDS_OMNI_Production", "_Environments",workspace=workspace_ID)&lt;BR /&gt;---&amp;gt; 13 df_table.to_lakehouse_table("Environments", "overwrite")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;File ~/cluster-env/trident_env/lib/python3.10/site-packages/sempy/_utils/_log.py:273, in mds_log.&amp;lt;locals&amp;gt;.get_wrapper.&amp;lt;locals&amp;gt;.log_decorator_wrapper(*args, **kwargs)&lt;BR /&gt;270 raise&lt;BR /&gt;272 try:&lt;BR /&gt;--&amp;gt; 273 result = func(*args, **kwargs)&lt;BR /&gt;275 # The invocation for get_message_dict moves after the function&lt;BR /&gt;276 # so it can access the state after the method call&lt;BR /&gt;277 message.update(extractor.get_completion_message_dict(result, arg_dict))&lt;/P&gt;&lt;P&gt;File ~/cluster-env/trident_env/lib/python3.10/site-packages/sempy/fabric/_dataframe/_fabric_dataframe.py:559, in FabricDataFrame.to_lakehouse_table(self, name, mode, spark_schema)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;550 with SparkConfigTemporarily(spark, "spark.sql.parquet.int96RebaseModeInWrite", "CORRECTED"):&lt;BR /&gt;551 spark_df = spark.createDataFrame(df_converted, schema=converted_schema)&lt;BR /&gt;553 (spark_df.write&lt;BR /&gt;554 .option("parquet.vorder.enabled", True)&lt;BR /&gt;555 .mode(mode)&lt;BR /&gt;556 .format("delta")&lt;BR /&gt;557 # enable column mapping to support special characters common w/ Power BI (e.g. [])&lt;BR /&gt;558 .option("delta.columnMapping.mode", "name")&lt;BR /&gt;--&amp;gt; 559 .saveAsTable(name))&lt;/P&gt;&lt;P&gt;File /opt/spark/python/lib/pyspark.zip/pyspark/sql/readwriter.py:1521, in DataFrameWriter.saveAsTable(self, name, format, mode, partitionBy, **options)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;1519 if format is not None:&lt;BR /&gt;1520 self.format(format)&lt;BR /&gt;-&amp;gt; 1521 self._jwrite.saveAsTable(name)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;File ~/cluster-env/trident_env/lib/python3.10/site-packages/py4j/java_gateway.py:1322, in JavaMember.__call__(self, *args)&lt;BR /&gt;1316 command = proto.CALL_COMMAND_NAME +\&lt;BR /&gt;1317 self.command_header +\&lt;BR /&gt;1318 args_command +\&lt;BR /&gt;1319 proto.END_COMMAND_PART&lt;BR /&gt;1321 answer = self.gateway_client.send_command(command)&lt;BR /&gt;-&amp;gt; 1322 return_value = get_return_value(&lt;BR /&gt;1323 answer, self.gateway_client, self.target_id, self.name)&lt;BR /&gt;1325 for temp_arg in temp_args:&lt;BR /&gt;1326 if hasattr(temp_arg, "_detach"):&lt;/P&gt;&lt;P&gt;File /opt/spark/python/lib/pyspark.zip/pyspark/errors/exceptions/captured.py:175, in capture_sql_exception.&amp;lt;locals&amp;gt;.deco(*a, **kw)&lt;BR /&gt;171 converted = convert_exception(e.java_exception)&lt;BR /&gt;172 if not isinstance(converted, UnknownException):&lt;BR /&gt;173 # Hide where the exception came from that shows a non-Pythonic&lt;BR /&gt;174 # JVM exception message.&lt;BR /&gt;--&amp;gt; 175 raise converted from None&lt;BR /&gt;176 else:&lt;BR /&gt;177 raise&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Fri, 16 Aug 2024 09:05:42 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-08-16T09:05:42Z</dc:date>
    <item>
      <title>Load data from Semantic Model to Lakehouse where semantic model column names start with Capitals</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Science/Load-data-from-Semantic-Model-to-Lakehouse-where-semantic-model/m-p/4103951#M265</link>
      <description>&lt;P&gt;Hi there - trying to lload a tabe from a semantic model to a lakehouse but the issue is that the table in the semantic model I want to load from has column names that start with Capital letters (for ease of use).&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Obviously this breaks the rules of lakehouse tables&amp;nbsp; - how do i fix this - ideally dynamically ?&lt;BR /&gt;&lt;BR /&gt;Code below&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;EM&gt;import sempy.fabric as fabric&lt;/EM&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;EM&gt;#Dev&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;#workspace_ID = "XXXXXX"&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;#Stage&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;#workspace_ID = "XXXXXX"&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;#Prod&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;workspace_ID = "XXXXXX"&lt;/EM&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;EM&gt;workspace_Safe_ID = workspace_ID.replace("-","_")&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;df_table = fabric.read_table("PSG_CTD_GDS_OMNI_Production", "_Environments",workspace=workspace_ID)&lt;/EM&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;EM&gt;df_table.to_lakehouse_table("Environments", "overwrite")&lt;BR /&gt;&lt;BR /&gt;&lt;/EM&gt;And error log&amp;nbsp;&lt;BR /&gt;&lt;P&gt;Cell In[8], line 13&lt;BR /&gt;10 workspace_Safe_ID = workspace_ID.replace("-","_")&lt;BR /&gt;11 df_table = fabric.read_table("PSG_CTD_GDS_OMNI_Production", "_Environments",workspace=workspace_ID)&lt;BR /&gt;---&amp;gt; 13 df_table.to_lakehouse_table("Environments", "overwrite")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;File ~/cluster-env/trident_env/lib/python3.10/site-packages/sempy/_utils/_log.py:273, in mds_log.&amp;lt;locals&amp;gt;.get_wrapper.&amp;lt;locals&amp;gt;.log_decorator_wrapper(*args, **kwargs)&lt;BR /&gt;270 raise&lt;BR /&gt;272 try:&lt;BR /&gt;--&amp;gt; 273 result = func(*args, **kwargs)&lt;BR /&gt;275 # The invocation for get_message_dict moves after the function&lt;BR /&gt;276 # so it can access the state after the method call&lt;BR /&gt;277 message.update(extractor.get_completion_message_dict(result, arg_dict))&lt;/P&gt;&lt;P&gt;File ~/cluster-env/trident_env/lib/python3.10/site-packages/sempy/fabric/_dataframe/_fabric_dataframe.py:559, in FabricDataFrame.to_lakehouse_table(self, name, mode, spark_schema)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;550 with SparkConfigTemporarily(spark, "spark.sql.parquet.int96RebaseModeInWrite", "CORRECTED"):&lt;BR /&gt;551 spark_df = spark.createDataFrame(df_converted, schema=converted_schema)&lt;BR /&gt;553 (spark_df.write&lt;BR /&gt;554 .option("parquet.vorder.enabled", True)&lt;BR /&gt;555 .mode(mode)&lt;BR /&gt;556 .format("delta")&lt;BR /&gt;557 # enable column mapping to support special characters common w/ Power BI (e.g. [])&lt;BR /&gt;558 .option("delta.columnMapping.mode", "name")&lt;BR /&gt;--&amp;gt; 559 .saveAsTable(name))&lt;/P&gt;&lt;P&gt;File /opt/spark/python/lib/pyspark.zip/pyspark/sql/readwriter.py:1521, in DataFrameWriter.saveAsTable(self, name, format, mode, partitionBy, **options)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;1519 if format is not None:&lt;BR /&gt;1520 self.format(format)&lt;BR /&gt;-&amp;gt; 1521 self._jwrite.saveAsTable(name)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;File ~/cluster-env/trident_env/lib/python3.10/site-packages/py4j/java_gateway.py:1322, in JavaMember.__call__(self, *args)&lt;BR /&gt;1316 command = proto.CALL_COMMAND_NAME +\&lt;BR /&gt;1317 self.command_header +\&lt;BR /&gt;1318 args_command +\&lt;BR /&gt;1319 proto.END_COMMAND_PART&lt;BR /&gt;1321 answer = self.gateway_client.send_command(command)&lt;BR /&gt;-&amp;gt; 1322 return_value = get_return_value(&lt;BR /&gt;1323 answer, self.gateway_client, self.target_id, self.name)&lt;BR /&gt;1325 for temp_arg in temp_args:&lt;BR /&gt;1326 if hasattr(temp_arg, "_detach"):&lt;/P&gt;&lt;P&gt;File /opt/spark/python/lib/pyspark.zip/pyspark/errors/exceptions/captured.py:175, in capture_sql_exception.&amp;lt;locals&amp;gt;.deco(*a, **kw)&lt;BR /&gt;171 converted = convert_exception(e.java_exception)&lt;BR /&gt;172 if not isinstance(converted, UnknownException):&lt;BR /&gt;173 # Hide where the exception came from that shows a non-Pythonic&lt;BR /&gt;174 # JVM exception message.&lt;BR /&gt;--&amp;gt; 175 raise converted from None&lt;BR /&gt;176 else:&lt;BR /&gt;177 raise&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 16 Aug 2024 09:05:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Science/Load-data-from-Semantic-Model-to-Lakehouse-where-semantic-model/m-p/4103951#M265</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-08-16T09:05:42Z</dc:date>
    </item>
    <item>
      <title>Re: Load data from Semantic Model to Lakehouse where semantic model column names start with Capitals</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Science/Load-data-from-Semantic-Model-to-Lakehouse-where-semantic-model/m-p/4104693#M276</link>
      <description>&lt;P&gt;ChatGPT helped me with this. The main item in the code is this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;df_lower = df.toDF(*[c.lower() for c in df.columns])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ChatGPT created this example:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;# Example DataFrame
data = [("John", 28), ("Alice", 23), ("Bob", 35)]
columns = ["Name", "Age"]
df = spark.createDataFrame(data, columns)

# Convert all column names to lowercase
df_lower = df.toDF(*[c.lower() for c in df.columns])

# Show the resulting DataFrame
df_lower.show()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Explanation:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;df.columns: Retrieves the list of column names.&lt;/LI&gt;&lt;LI&gt;[c.lower() for c in df.columns]: Converts each column name to lowercase.&lt;/LI&gt;&lt;LI&gt;df.toDF(*[c.lower() for c in df.columns]): Creates a new DataFrame with the lowercase column names.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;This will rename all columns in the DataFrame to their lowercase equivalents.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a StackOverflow thread mentioning the same method. Perhaps ChatGPT learned from it:&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/43005744/convert-columns-of-pyspark-data-frame-to-lowercase" target="_blank" rel="nofollow noopener noreferrer"&gt;https://stackoverflow.com/questions/43005744/convert-columns-of-pyspark-data-frame-to-lowercase&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So in your case, the code could be like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;import sempy.fabric as fabric

#Dev
#workspace_ID = "XXXXXX"
#Stage
#workspace_ID = "XXXXXX"
#Prod
workspace_ID = "XXXXXX"

workspace_Safe_ID = workspace_ID.replace("-","_")
df_table = fabric.read_table("PSG_CTD_GDS_OMNI_Production", "_Environments",workspace=workspace_ID)
df_lower = df_table.toDF(*[c.lower() for c in df_table.columns])

df_lower.to_lakehouse_table("Environments", "overwrite")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 18:28:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Science/Load-data-from-Semantic-Model-to-Lakehouse-where-semantic-model/m-p/4104693#M276</guid>
      <dc:creator>frithjof_v</dc:creator>
      <dc:date>2024-08-16T18:28:16Z</dc:date>
    </item>
    <item>
      <title>Re: Load data from Semantic Model to Lakehouse where semantic model column names start with Capitals</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Science/Load-data-from-Semantic-Model-to-Lakehouse-where-semantic-model/m-p/4110741#M278</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you have a chance to try&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="437984" data-lia-user-login="frithjof_v" class="lia-mention lia-mention-user"&gt;frithjof_v&lt;/a&gt;&amp;nbsp;'s solution? Does it work or not? Or did you find any other solution? Let us know if you have any questions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Jing&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2024 08:34:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Science/Load-data-from-Semantic-Model-to-Lakehouse-where-semantic-model/m-p/4110741#M278</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-08-21T08:34:42Z</dc:date>
    </item>
  </channel>
</rss>

