Skip to content

Commit 7cfa7d2

Browse files
Added Tabular Editor x Databricks scripts (#190)
* Added Tabular Editor x Databricks scripts Added pages for 3 new scripts Added images to be referenced in scripts Updated advanced library landing page
1 parent 964d6f9 commit 7cfa7d2

10 files changed

Lines changed: 1285 additions & 2 deletions
6.32 KB
Loading
76.7 KB
Loading
37.8 KB
Loading
5.74 KB
Loading
7.4 KB
Loading

‎content/common/CSharpScripts/Advanced/script-add-databricks-metadata-descriptions.md‎

Lines changed: 573 additions & 0 deletions
Large diffs are not rendered by default.

‎content/common/CSharpScripts/Advanced/script-create-databricks-relationships.md‎

Lines changed: 609 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
uid: script-databricks-semantic-model-set-up
3+
title: Databricks Semantic Model Set-Up
4+
author: Johnny Winter
5+
updated: 2025-09-04
6+
applies_to:
7+
versions:
8+
- version: 2.x
9+
- version: 3.x
10+
---
11+
# Databricks Semantic Model Set-Up
12+
13+
## Script Purpose
14+
This script was created as part of the Tabular Editor x Databricks series. In Databricks Unity Catalog it is not possible to use capital letters in table names. A common way to make tables names more readable without using capital letters is to adopt snake_case. Also, whilst column names can contain spaces, it is often advised against as these can be cumbersome to work with, meaning data engineers most often use snake_case, camelCase or PascalCase.
15+
16+
However, we want users of our Semantic Model to see business friendly names in our model.
17+
18+
The following script will loop through all tables in the model and make sure friendly, Proper Case formatting is applied.
19+
20+
Whilst doing this, it will also apply some best practice recommendations, setting default summarisation for all columns to none and also setting format strings for DateTime type fields (this script is set up to use format ‘yyyy-mm-dd' but you can alter the script at line 61 if you prefer)
21+
<br></br>
22+
> [!NOTE]
23+
> This script is not strictly for use with only Databricks – use it with any model you like, regardless of data source, but it has been built with some of the limitations of Databricks in mind.
24+
<br></br>
25+
## Script
26+
27+
### Databricks Semantic Model Set-Up
28+
```csharp
29+
/*
30+
* Title: Databricks Semantic Model Set-Up
31+
* Author: Johnny Winter, greyskullanalytics.com
32+
*
33+
* This script, when executed, will loop through all tables and columns in the model and rename with friendly names.
34+
* Names in snake_case, camelCase or PascalCase will all be converted to Proper Case.
35+
* No table selections are required as all tables in the model will be processed, simply run the script.
36+
* Whilst looping though columns it also sets default summarization to none and sets a format string for all DateTime type fields
37+
* (currently it sets format 'yyyy-mm-dd' but you can change this on line 61 if you wish).
38+
*
39+
*/
40+
using System;
41+
using System.Globalization;
42+
43+
//create script as class so it can be reused
44+
class p {
45+
46+
public static void ConvertCase(dynamic obj)
47+
{
48+
TextInfo textInfo = CultureInfo.CurrentCulture.TextInfo;
49+
//replace underscores with a space
50+
var oldName = obj.Name.Replace("_", " ");
51+
var newName = new System.Text.StringBuilder();
52+
for(int i = 0; i < oldName.Length; i++) {
53+
// First letter should always be capitalized:
54+
if(i == 0) newName.Append(Char.ToUpper(oldName[i]));
55+
56+
// A sequence of two uppercase letters followed by a lowercase letter should have a space inserted
57+
// after the first letter:
58+
else if(i + 2 < oldName.Length && char.IsLower(oldName[i + 2]) && char.IsUpper(oldName[i + 1]) && char.IsUpper(oldName[i]))
59+
{
60+
newName.Append(oldName[i]);
61+
newName.Append(" ");
62+
}
63+
64+
// All other sequences of a lowercase letter followed by an uppercase letter, should have a space
65+
// inserted after the first letter:
66+
else if(i + 1 < oldName.Length && char.IsLower(oldName[i]) && char.IsUpper(oldName[i+1]))
67+
{
68+
newName.Append(oldName[i]);
69+
newName.Append(" ");
70+
}
71+
else
72+
{
73+
newName.Append(oldName[i]);
74+
}
75+
}
76+
//apply Proper Case where this has not already been taken care of above
77+
obj.Name = textInfo.ToTitleCase(newName.ToString());
78+
}
79+
}
80+
81+
foreach(var t in Model.Tables) {
82+
//convert table names
83+
p.ConvertCase(t);
84+
//convert column names
85+
foreach(var c in t.Columns) {
86+
p.ConvertCase(c);
87+
c.SummarizeBy = AggregateFunction.None;
88+
if (c.DataType == DataType.DateTime)
89+
{c.FormatString = "yyyy-mm-dd";}
90+
}
91+
}
92+
```
93+
### Explanation
94+
This script, when executed, will loop through all tables and columns in the model and rename with friendly names. Names in snake_case, camelCase or PascalCase will all be converted to Proper Case. No table selections are required as all tables in the model will be processed, simply run the script. Whilst looping though columns it also sets default summarization to none and sets a format string for all DateTime type fields.
95+

‎content/common/CSharpScripts/csharp-script-library-advanced.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
uid: script-library-advanced
33
title: Advanced C# Scripts
4-
updated: 2023-02-27
4+
updated: 2025-09-04
55
applies_to:
66
versions:
77
- version: 2.x
@@ -24,4 +24,7 @@ These are more advanced scripts with sophisticated functionalities requiring a m
2424
| [Format Power Query](xref:script-format-power-query) | Formats the Power Query of a selected M Partition by using the powerqueryformatter.com API. | When you have complex Power Query and need to make it more readable for reading or making changes. |
2525
| [Implement Incremental Refresh](xref:script-implement-incremental-refresh) | Configures Incremental Refresh automatically using parameters from a UI dialogue box. | When you need to implement incremental refresh but aren't comfortable with the configuration in the table settings. |
2626
| [Remove Measures with Errors](xref:script-remove-measures-with-error) | Creates a new M Parameter and automatically adds it to M Partitions. | When you want to replace strings in multiple partitions (i.e. connection strings) with a dynamic M Parameter. |
27-
| [Find & Replace in Selected Measures](xref:script-find-replace) | Searches for a substring in the DAX of selected measures, replacing with another substring. | When you need to quickly find/replace values in multiple DAX measures (i.e. `CALCULATE` filter or broken object references). |
27+
| [Find & Replace in Selected Measures](xref:script-find-replace) | Searches for a substring in the DAX of selected measures, replacing with another substring. | When you need to quickly find/replace values in multiple DAX measures (i.e. `CALCULATE` filter or broken object references). |
28+
| [Databricks Semantic Model Set-up](xref:script-databricks-semantic-model-set-up) | Friendly name tables and columns and set column best practices | When your Databricks object names need making more user friendly. |
29+
| [Create Databricks Relationships](xref:script-create-databricks-relationships) | Create relationships based on primary and foreign key definitions in Databricks Unity Catalog | When you want to re-use Databricks relationship definitions that have already been defined in Unity Catalog. |
30+
| [Add Databricks Metadata Descriptions](xref:script-add-databricks-metadata-descriptions) | Update table and column descriptions based on Databricks Unity Catalog | When you want to re-use Databricks table and column comments that have already been defined in Unity Catalog. |

‎content/common/toc.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,8 @@
4343
#### @script-find-replace
4444
#### @script-convert-dlsql-to-dlol
4545
#### @script-convert-import-to-dlol
46+
#### @script-databricks-semantic-model-set-up
47+
#### @script-create-databricks-relationships
48+
#### @script-add-databricks-metadata-descriptions
4649

4750
## @script-helper-methods

0 commit comments

Comments
 (0)