Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

How to create a Materialized View in Lakehouse? not in KQL Database

I have below code and want to create a Materialized View for it:

spark.sql("SELECT * FROM ParquetRainfallTable WHERE month == 'Apr' AND  \
          location = 'Clementi Road' ORDER BY rainfall desc").show(5)
 
## below is for Materialized View, but failed
# Create the Materialized View for Rainfall data
query = """
CREATE MATERIALIZED VIEW IF NOT EXISTS AprilRainfall_mv
AS
SELECT * FROM ParquetRainfallTable WHERE month == 'Apr' AND  
         location = 'Clementi Road' ORDER BY rainfall desc
"""
spark.sql(query)
 
ParseException: [PARSE_SYNTAX_ERROR] Syntax error at or near 'MATERIALIZED'.(line 2, pos 7) == SQL == CREATE MATERIALIZED VIEW IF NOT EXISTS AprilRainfall_mv -------^^^ AS SELECT * FROM ParquetRainfallTable WHERE month == 'Apr' AND location = 'Clementi Road' ORDER BY rainfall desc
 
So, does Fabric Lakehouse support CREATE MATERIALIZED VIEW in Spark SQL??

 

1 ACCEPTED SOLUTION
nilendraFabric
Super User
Super User

Hello @Anonymous 

 

the Spark SQL engine in Fabric Lakehouse does not recognize the materialized view syntax. In Microsoft Fabric, while materialized views exist, they are not created using the standard Spark SQL statement. Instead, materialized views in Fabric are designed to be created through a KQL-based interface


in kusto query: 

.create materialized-view [ifnotexists] <ViewName> on table <SourceTable>
{
// Your summarize-based aggregation query here
}

 

use %kusto magic command 

 

if this is helpful please accept the solution 

View solution in original post

2 REPLIES 2
FilipAi
Helper I
Helper I

First of all I would remove one of the equal signs in the WHERE clause, to make it read "month = 'Apr'". Does the error still persist after that?

nilendraFabric
Super User
Super User

Hello @Anonymous 

 

the Spark SQL engine in Fabric Lakehouse does not recognize the materialized view syntax. In Microsoft Fabric, while materialized views exist, they are not created using the standard Spark SQL statement. Instead, materialized views in Fabric are designed to be created through a KQL-based interface


in kusto query: 

.create materialized-view [ifnotexists] <ViewName> on table <SourceTable>
{
// Your summarize-based aggregation query here
}

 

use %kusto magic command 

 

if this is helpful please accept the solution 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

June FBC25 Carousel

Fabric Monthly Update - June 2025

Check out the June 2025 Fabric update to learn about new features.