<?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: &amp;quot;Detected schema change&amp;quot; error while reading from delta table in streaming after applying  &amp;quot;ALTER COLUMN DROP NOT NULL&amp;quot; to more than one columns. in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/quot-detected-schema-change-quot-error-while-reading-from-delta/m-p/25154#M17461</link>
    <description>&lt;P&gt;DBR 10.4 LTS.&lt;/P&gt;&lt;P&gt;Also tested on 11.3 LTS - same result.&lt;/P&gt;</description>
    <pubDate>Mon, 31 Oct 2022 13:45:45 GMT</pubDate>
    <dc:creator>Anatoly</dc:creator>
    <dc:date>2022-10-31T13:45:45Z</dc:date>
    <item>
      <title>"Detected schema change" error while reading from delta table in streaming after applying  "ALTER COLUMN DROP NOT NULL" to more than one columns.</title>
      <link>https://community.databricks.com/t5/data-engineering/quot-detected-schema-change-quot-error-while-reading-from-delta/m-p/25148#M17455</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;I have a delta table and a process that reading a stream from this table.&lt;/P&gt;&lt;P&gt;I need to drop the NOT NULL constraint from some of the columns of this table.&lt;/P&gt;&lt;P&gt;The first drop command does not affect the reading stream.&lt;/P&gt;&lt;P&gt;But the second command results in error: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;StreamingQueryException: Detected schema change:
old schema: root
-- a: string (nullable = true)
-- b: string (nullable = true)
-- c: timestamp (nullable = false)
&amp;nbsp;
&amp;nbsp;
new schema: root
-- a: string (nullable = true)
-- b: string (nullable = false)
-- c: timestamp (nullable = false)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Full python notebook:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;# Databricks notebook source
# MAGIC %sql
# MAGIC CREATE SCHEMA temp_schema
&amp;nbsp;
# COMMAND ----------
&amp;nbsp;
# MAGIC %sql
# MAGIC CREATE TABLE temp_schema.temp_stream_table (
# MAGIC   a STRING NOT NULL,
# MAGIC   b STRING NOT NULL,
# MAGIC   c TIMESTAMP NOT NULL
# MAGIC   )
# MAGIC LOCATION "dbfs:/tmp/temp_stream_table"
&amp;nbsp;
# COMMAND ----------
&amp;nbsp;
# MAGIC %sql
# MAGIC INSERT INTO temp_schema.temp_stream_table
# MAGIC VALUES ("a", "b", CURRENT_DATE), ("c", "d", CURRENT_DATE)
&amp;nbsp;
# COMMAND ----------
&amp;nbsp;
def run_stream():
    return (
      spark
     .readStream
     .option("mergeSchema", "true")
     .table("temp_schema.temp_stream_table")
     .writeStream
     .trigger(availableNow=True)
     .option("checkpointLocation", "/dbfs/tmp/temp_stream_checkpoint")
     .foreachBatch(lambda df, _id: None)
     .start()
     .awaitTermination()
    )
&amp;nbsp;
# COMMAND ----------
&amp;nbsp;
run_stream()
&amp;nbsp;
# COMMAND ----------
&amp;nbsp;
# MAGIC %sql
# MAGIC ALTER TABLE temp_schema.temp_stream_table
# MAGIC ALTER COLUMN a DROP NOT NULL;
&amp;nbsp;
# COMMAND ----------
&amp;nbsp;
run_stream()
# Success!
&amp;nbsp;
# COMMAND ----------
&amp;nbsp;
# MAGIC %sql
# MAGIC ALTER TABLE temp_schema.temp_stream_table
# MAGIC ALTER COLUMN b DROP NOT NULL;
&amp;nbsp;
# COMMAND ----------
&amp;nbsp;
run_stream()
### Failure here: StreamingQueryException: Detected schema change ...
&amp;nbsp;
# COMMAND ----------
&amp;nbsp;
# MAGIC %sql
# MAGIC DROP TABLE temp_schema.temp_stream_table;
# MAGIC DROP SCHEMA temp_schema
&amp;nbsp;
# COMMAND ----------
&amp;nbsp;
dbutils.fs.rm("dbfs:/tmp/temp_stream_checkpoint", True)
dbutils.fs.rm("dbfs:/tmp/temp_stream_table", True)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is it a bug?&lt;/P&gt;</description>
      <pubDate>Sun, 30 Oct 2022 10:29:11 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/quot-detected-schema-change-quot-error-while-reading-from-delta/m-p/25148#M17455</guid>
      <dc:creator>Anatoly</dc:creator>
      <dc:date>2022-10-30T10:29:11Z</dc:date>
    </item>
    <item>
      <title>Re: "Detected schema change" error while reading from delta table in streaming after applying  "ALTER COLUMN DROP NOT NULL" to more than one columns.</title>
      <link>https://community.databricks.com/t5/data-engineering/quot-detected-schema-change-quot-error-while-reading-from-delta/m-p/25150#M17457</link>
      <description>&lt;P&gt;Hi @Kaniz Fatma​&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I cleanup the checkpoint directory in rows 71-12, it  should be empty.&lt;/P&gt;&lt;P&gt;Also no new data is inserted into table, the error is on read.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 13:07:18 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/quot-detected-schema-change-quot-error-while-reading-from-delta/m-p/25150#M17457</guid>
      <dc:creator>Anatoly</dc:creator>
      <dc:date>2022-10-31T13:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: "Detected schema change" error while reading from delta table in streaming after applying  "ALTER COLUMN DROP NOT NULL" to more than one columns.</title>
      <link>https://community.databricks.com/t5/data-engineering/quot-detected-schema-change-quot-error-while-reading-from-delta/m-p/25152#M17459</link>
      <description>&lt;P&gt;Yes, for field "b". nullable=true vs nullable=false&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 13:13:18 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/quot-detected-schema-change-quot-error-while-reading-from-delta/m-p/25152#M17459</guid>
      <dc:creator>Anatoly</dc:creator>
      <dc:date>2022-10-31T13:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: "Detected schema change" error while reading from delta table in streaming after applying  "ALTER COLUMN DROP NOT NULL" to more than one columns.</title>
      <link>https://community.databricks.com/t5/data-engineering/quot-detected-schema-change-quot-error-while-reading-from-delta/m-p/25154#M17461</link>
      <description>&lt;P&gt;DBR 10.4 LTS.&lt;/P&gt;&lt;P&gt;Also tested on 11.3 LTS - same result.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 13:45:45 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/quot-detected-schema-change-quot-error-while-reading-from-delta/m-p/25154#M17461</guid>
      <dc:creator>Anatoly</dc:creator>
      <dc:date>2022-10-31T13:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: "Detected schema change" error while reading from delta table in streaming after applying  "ALTER COLUMN DROP NOT NULL" to more than one columns.</title>
      <link>https://community.databricks.com/t5/data-engineering/quot-detected-schema-change-quot-error-while-reading-from-delta/m-p/25155#M17462</link>
      <description>&lt;P&gt;@Kaniz Fatma​&amp;nbsp; The command used to drop constraint is:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;ALTER TABLE temp_schema.temp_stream_table
ALTER COLUMN a DROP NOT NULL;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This means, I want to make the column nullable, not to drop it.&lt;/P&gt;&lt;P&gt;The error appears on readStream step, not on drop constraint.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 14:04:11 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/quot-detected-schema-change-quot-error-while-reading-from-delta/m-p/25155#M17462</guid>
      <dc:creator>Anatoly</dc:creator>
      <dc:date>2022-10-31T14:04:11Z</dc:date>
    </item>
    <item>
      <title>Re: "Detected schema change" error while reading from delta table in streaming after applying  "ALTER COLUMN DROP NOT NULL" to more than one columns.</title>
      <link>https://community.databricks.com/t5/data-engineering/quot-detected-schema-change-quot-error-while-reading-from-delta/m-p/25157#M17464</link>
      <description>&lt;P&gt;Hi @Anatoly Tikhonov​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope everything is going great.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does @Kaniz Fatma​&amp;nbsp; response answer your question? If yes, would you be happy to mark it as best so that other members can find the solution more quickly?&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;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jan 2023 05:59:43 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/quot-detected-schema-change-quot-error-while-reading-from-delta/m-p/25157#M17464</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-01-09T05:59:43Z</dc:date>
    </item>
  </channel>
</rss>

