<?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 Re: Error in SQL statement: AnalysisException: Cannot up cast documents from array in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29069#M20826</link>
    <description>&lt;P&gt;Thank you @Werner Stinckens​&amp;nbsp;, but it does not help much. The article you've linked explains new features of Databricks Runtime 3.0 for working with complex data types. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am simply selecting a single column with a simple data type from a view that also has a column with complex data type. This query should not be failing like that. I hope this makes sense.&lt;/P&gt;</description>
    <pubDate>Thu, 06 Oct 2022 16:18:47 GMT</pubDate>
    <dc:creator>sage5616</dc:creator>
    <dc:date>2022-10-06T16:18:47Z</dc:date>
    <item>
      <title>Error in SQL statement: AnalysisException: Cannot up cast documents from array</title>
      <link>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29067#M20824</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am getting the following error when running a SQL query and do not understand what it means or what can be done to resolve it. Any recommendations?&lt;/P&gt;&lt;P&gt;View DDL:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;CREATE VIEW myschema.table (
  accountId,
  agreementType,
  capture_file_name,
  capture_file_path,
  createdDate,
  currency,
  de_agentid,
  de_applicationshardid,
  de_datacontenttype,
  de_eventapplicationtime,
  de_eventmode,
  de_eventpublishtime,
  de_eventsequenceid,
  de_id,
  de_partitionkey,
  de_source,
  documents,
  effectiveDate,
  eh_EnqueuedTimeUtc,
  eh_Offset,
  eh_SequenceNumber,
  eh_SystemProperties_x_opt_enqueued_time,
  eh_SystemProperties_x_opt_kafka_key,
  endDate,
  expirationDate,
  externalId,
  externalSource,
  id,
  isInWorkflow,
  isSigned,
  name,
  notice,
  noticeDate,
  noticePeriod,
  parties,
  reconciled_file_name_w_path,
  requestor,
  resourceVersion,
  status,
  terminateForConvenience,
  updatedDate,
  value,
  de_action,
  de_eventapplication_year,
  de_eventapplication_month,
  de_eventapplication_day,
  de_eventapplication_hour,
  de_eventapplication_minute)
TBLPROPERTIES (
  'transient_lastDdlTime' = '1664473495')
AS select * from parquet.`/mnt/store/de_entitytype=Agreement`&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SQL query:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;select de_id from myschema.table;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Error:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Error in SQL statement: AnalysisException: Cannot up cast documents from array&amp;lt;struct&amp;lt;accountId:string,agreementId:string,createdBy:string,createdDate:string,id:string,obligations:array&amp;lt;string&amp;gt;,resourceVersion:bigint,updatedBy:string,updatedDate:string&amp;gt;&amp;gt; to array&amp;lt;string&amp;gt;.
The type path of the target object is:
&amp;nbsp;
You can either add an explicit cast to the input data or choose a higher precision type of the field in the target object&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any recommendations on how to resolve this error would be much appreciated &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2022 19:45:31 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29067#M20824</guid>
      <dc:creator>sage5616</dc:creator>
      <dc:date>2022-10-05T19:45:31Z</dc:date>
    </item>
    <item>
      <title>Re: Error in SQL statement: AnalysisException: Cannot up cast documents from array</title>
      <link>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29068#M20825</link>
      <description>&lt;P&gt;Seems like the nested struct gives you some issues.&lt;/P&gt;&lt;P&gt;Can you check &lt;A href="https://www.databricks.com/blog/2017/05/24/working-with-nested-data-using-higher-order-functions-in-sql-on-databricks.html" alt="https://www.databricks.com/blog/2017/05/24/working-with-nested-data-using-higher-order-functions-in-sql-on-databricks.html" target="_blank"&gt;this&lt;/A&gt; to see if it helps?&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 08:01:49 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29068#M20825</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2022-10-06T08:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: Error in SQL statement: AnalysisException: Cannot up cast documents from array</title>
      <link>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29069#M20826</link>
      <description>&lt;P&gt;Thank you @Werner Stinckens​&amp;nbsp;, but it does not help much. The article you've linked explains new features of Databricks Runtime 3.0 for working with complex data types. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am simply selecting a single column with a simple data type from a view that also has a column with complex data type. This query should not be failing like that. I hope this makes sense.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 16:18:47 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29069#M20826</guid>
      <dc:creator>sage5616</dc:creator>
      <dc:date>2022-10-06T16:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Error in SQL statement: AnalysisException: Cannot up cast documents from array</title>
      <link>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29070#M20827</link>
      <description>&lt;P&gt;Sorry, I missed the select query.&lt;/P&gt;&lt;P&gt;Can you check if the view returns data when using the explorer (so in the Data tab)?  Maybe it is corrupt.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Oct 2022 08:22:15 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29070#M20827</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2022-10-10T08:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: Error in SQL statement: AnalysisException: Cannot up cast documents from array</title>
      <link>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29071#M20828</link>
      <description>&lt;P&gt;@Werner Stinckens​: Same error occurs in the explorer (so in the Data tab).&lt;/P&gt;</description>
      <pubDate>Mon, 10 Oct 2022 14:31:13 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29071#M20828</guid>
      <dc:creator>sage5616</dc:creator>
      <dc:date>2022-10-10T14:31:13Z</dc:date>
    </item>
    <item>
      <title>Re: Error in SQL statement: AnalysisException: Cannot up cast documents from array</title>
      <link>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29072#M20829</link>
      <description>&lt;P&gt;OK, that means the table/view does not correspond anymore to the actual data.&lt;/P&gt;&lt;P&gt;Can you create a temp view on the delta lake/parquet/... and run the same query?&lt;/P&gt;&lt;P&gt;It will probably work. And if it does, you will have to re-create the table to have a correct schema.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2022 08:23:01 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29072#M20829</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2022-10-11T08:23:01Z</dc:date>
    </item>
    <item>
      <title>Re: Error in SQL statement: AnalysisException: Cannot up cast documents from array</title>
      <link>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29073#M20830</link>
      <description>&lt;P&gt;Just read parquet in python and retrieve auto-generated DDL schema:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;parquetFile = spark.read.parquet("people.parquet")
parquetFile.createOrReplaceTempView("parquetFile")
schema_json = spark.sql("SELECT * FROM parquetFile").schema.json()
ddl = spark.sparkContext._jvm.org.apache.spark.sql.types.DataType.fromJson(schema_json).toDDL()
print(ddl)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2022 11:31:21 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29073#M20830</guid>
      <dc:creator>Hubert-Dudek</dc:creator>
      <dc:date>2022-10-14T11:31:21Z</dc:date>
    </item>
    <item>
      <title>Re: Error in SQL statement: AnalysisException: Cannot up cast documents from array</title>
      <link>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29074#M20831</link>
      <description>&lt;P&gt;I re-created the view and got a similar error. It looks like when the complex data type slightly changes (columns like "documents" in my original post), Spark view cannot handle that, which is not right.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2022 14:06:23 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29074#M20831</guid>
      <dc:creator>sage5616</dc:creator>
      <dc:date>2022-10-14T14:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: Error in SQL statement: AnalysisException: Cannot up cast documents from array</title>
      <link>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29075#M20832</link>
      <description>&lt;P&gt;Thank you for chiming in @Hubert Dudek​, but not sure how this helps with getting the view to read its parquet files when some of them have columns with structs and arrays with varying schemas, which is what appears to be the problem. &lt;/P&gt;&lt;P&gt;P.S.&lt;/P&gt;&lt;P&gt;I tried converting complex data types to strings, struct or arrays schema inside the column disappears leaving just the data values without their names.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2022 19:33:49 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29075#M20832</guid>
      <dc:creator>sage5616</dc:creator>
      <dc:date>2022-10-14T19:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: Error in SQL statement: AnalysisException: Cannot up cast documents from array</title>
      <link>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29076#M20833</link>
      <description>&lt;P&gt;It is helping in the way that it will give you the perfect schema &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; which you can copy paste to your code&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2022 12:35:26 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29076#M20833</guid>
      <dc:creator>Hubert-Dudek</dc:creator>
      <dc:date>2022-10-20T12:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: Error in SQL statement: AnalysisException: Cannot up cast documents from array</title>
      <link>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29078#M20835</link>
      <description>&lt;P&gt;Thanks again.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;I need to use Spark Persistent view. I don't think there is a way to specify the schema when creating Spark Persistent view, perhaps I don't know.&lt;/LI&gt;&lt;LI&gt;Copy/paste schema into my code is hard-coding, which will not work in my case. I need the schema determined dynamically as new partitions are added that the view sits on top of. Sometimes fields within a complex (datatype) column have no data, which apparently changes the schema of the entire complex column. Somehow, I need to get the Spark Persistent view to recognize that and handle this dynamically rather than failing.&lt;/LI&gt;&lt;LI&gt;Querying the same parquet files without a Spark Persistent view yields the same error. Flattening out columns with complex data type fields into separate simple data type columns takes care of the problem. &lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Fri, 28 Oct 2022 01:39:29 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29078#M20835</guid>
      <dc:creator>sage5616</dc:creator>
      <dc:date>2022-10-28T01:39:29Z</dc:date>
    </item>
    <item>
      <title>Re: Error in SQL statement: AnalysisException: Cannot up cast documents from array</title>
      <link>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29079#M20836</link>
      <description>&lt;P&gt;Hi @Michael Okulik​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope all is well! Just wanted to check in if you were able to resolve your issue and would you be happy to share the solution or &lt;B&gt;mark an answer as best&lt;/B&gt;? Else please let us know if you need more help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We'd love to hear from you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 07:04:55 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-in-sql-statement-analysisexception-cannot-up-cast/m-p/29079#M20836</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-11-14T07:04:55Z</dc:date>
    </item>
  </channel>
</rss>

