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

60 Days of Data Days! Live and on-demand sessions, challenges, study groups and more! And it's all FREE!. Join now. Learn more

Reply
smpa01
Community Champion
Community Champion

clusterBy does not work in dataframe API?

The following works in databricks but not in fabric. It works through DeltaTable API though. But why does it not work through dataframeAPI?

# write load at t - Create the table with clustering enabled from the start
(df.write.format("delta")
         .mode("overwrite")
         .clusterBy("id") # <--- ADD THIS LINE HERE to enable clustering at creation
         .saveAsTable(table_name) # Use the fully qualified name here for consistency
)

# AttributeError: 'DataFrameWriter' object has no attribute 'clusterBy'

DataFrameWriter Doc

 

 

 


========================
Did I answer your question? Mark my post as a solution!
Proud to be a Super User
My Custom Visualization Projects
โ€ข Plotting Live Sound: Live Sound
โ€ข Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
โ€ข Visual Capitalist: Working Hrs
โ€ข Others: Easing Graph, Animated Calendar
MayViz Submissions
โ€ข Week 1: View
โ€ข Week 2: View
โ€ข Week 3: View
โ€ข Week 4: View
========================
1 ACCEPTED SOLUTION
v-prasare
Community Support
Community Support

Hi @smpa01 ,

the .clusterBy() method on DataFrameWriter is not supported because Fabric uses a customized Spark runtime that limits certain APIs to ensure simplicity and compatibility within its managed environment. Unlike Databricks, which offers extended Delta Lake features directly through the PySpark DataFrameWriter, Fabric restricts clustering capabilities to SQL DDL and the DeltaTable API

 

 

Thanks,

Prashanth Are

MS Fabric community support

View solution in original post

2 REPLIES 2
v-prasare
Community Support
Community Support

Hi @smpa01 ,

the .clusterBy() method on DataFrameWriter is not supported because Fabric uses a customized Spark runtime that limits certain APIs to ensure simplicity and compatibility within its managed environment. Unlike Databricks, which offers extended Delta Lake features directly through the PySpark DataFrameWriter, Fabric restricts clustering capabilities to SQL DDL and the DeltaTable API

 

 

Thanks,

Prashanth Are

MS Fabric community support

smpa01
Community Champion
Community Champion

@v-prasare  without clusterBy in dataframe writer, I am guessing the clusterd files can't be written, if one intends to write only the raw files with the intention to create an external table.

 

df.write\
    .format("delta")\
    .mode("append")\
    .clustrBy (cluster by fields)\
    .save(file_path)

 


========================
Did I answer your question? Mark my post as a solution!
Proud to be a Super User
My Custom Visualization Projects
โ€ข Plotting Live Sound: Live Sound
โ€ข Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
โ€ข Visual Capitalist: Working Hrs
โ€ข Others: Easing Graph, Animated Calendar
MayViz Submissions
โ€ข Week 1: View
โ€ข Week 2: View
โ€ข Week 3: View
โ€ข Week 4: View
========================

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon โ€“ Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save โ‚ฌ200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.