This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import struct | |
import sqlalchemy | |
import pyodbc | |
import notebookutils | |
import sempy.fabric as fabric | |
import time | |
from pyspark.sql import functions as fn | |
from datetime import datetime | |
def create_engine(connection_string : str): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import struct | |
import sqlalchemy | |
import pyodbc | |
import notebookutils | |
import sempy.fabric as fabric | |
def create_engine(connection_string : str): | |
token = notebookutils.credentials.getToken('https://analysis.windows.net/powerbi/api').encode("UTF-16-LE") | |
token_struct = struct.pack(f'<I{len(token)}s', len(token), token) | |
SQL_COPT_SS_ACCESS_TOKEN = 1256 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Purpose: Print out details of partitions, files per partitions, and size per partition in GB. | |
from notebookutils import mssparkutils | |
# Define ABFSS path for your delta table. You can get ABFSS path of a delta table by simply right-clicking on table name and selecting COPY PATH from the list of options. | |
# Remove the path and the lakehouse name. | |
delta_table_path = "abfss://[email protected]/" | |
HowManyLogsIsTooManyLogs = 50 ## 50 feels like a biggest number | |
HowLargeALogCanBeBeforeItsAIssue= 1 ## Value in MB | |
# List all partitions for given delta table |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Purpose: Print out details of partitions, files per partitions, and size per partition in GB. | |
from notebookutils import mssparkutils | |
# Define ABFSS path for your delta table. You can get ABFSS path of a delta table by simply right-clicking on table name and selecting COPY PATH from the list of options. | |
# Remove the path and the lakehouse name. | |
delta_table_path = "abfss://[email protected]/" | |
HowManyLogsIsTooManyLogs = 50 ## 50 feels like a biggest number | |
HowLargeALogCanBeBeforeItsAIssue= 1 ## Value in MB | |
# List all partitions for given delta table |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Purpose: Print out details of partitions, files per partitions, and size per partition in GB. | |
from notebookutils import mssparkutils | |
# Define ABFSS path for your delta table. You can get ABFSS path of a delta table by simply right-clicking on table name and selecting COPY PATH from the list of options. | |
delta_table_path = "abfss://ITEM_NAME@ONELAKE_PATH.fabric.microsoft.com/YOURLAKEHOUSE_NAME.Lakehouse/Tables" | |
# List all partitions for given delta table | |
tables_list = mssparkutils.fs.ls(delta_table_path) | |
# Initialize a dictionary to store partition details |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import struct | |
import sqlalchemy | |
import pyodbc | |
import notebookutils | |
def create_engine(connection_string : str): | |
token = notebookutils.credentials.getToken('https://analysis.windows.net/powerbi/api').encode("UTF-16-LE") | |
token_struct = struct.pack(f'<I{len(token)}s', len(token), token) | |
SQL_COPT_SS_ACCESS_TOKEN = 1256 | |
return sqlalchemy.create_engine("mssql+pyodbc://", creator=lambda: pyodbc.connect(connection_string, attrs_before={SQL_COPT_SS_ACCESS_TOKEN: token_struct})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
IF OBJECT_ID('mpmtest') IS NOT NULL | |
BEGIN; | |
DROP TABLE mpmtest | |
END | |
declare @path varchar(400), @dt datetime2, @credential varchar(500),@outputable varchar(500),@display int, @debug int; | |
set @path = 'https://cstestwss.blob.core.windows.net/csetestws/delta/demo/' | |
--set @dt = convert(datetime2,'2022/07/06 18:37:00'); --getdate(); -- for time travel -- | |
set @dt = getdate(); -- for time travel -- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create proc import_data as | |
begin | |
declare @dummy_datetime datetime2 ; | |
declare @sSQL varchar(8000); | |
if exists ( | |
select 1 from sys.schemas s inner join sys.tables t | |
on s.schema_id = t.schema_id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create PROC [dbo].[create_external_table_from_table] @tbname [varchar](200),@schema [varchar](200),@storageacc [varchar](200), | |
@datafolder [varchar](400),@fileformat [varchar](400),@external_Table_Name [varchar](200),@external_Table_Schema_Name [varchar](200) AS | |
BEGIN | |
SET NOCOUNT ON | |
/* | |
This proc creates an external table based on the shape of the table we want to import into. | |
Usage: | |
exec [dbo].[create_external_table_from_table]] 'tablename','schema','MyAzureStorage','/path/path/file.csv','FormatCSV','external_tbl_name','ext_schema' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE PROC [dbo].[sp_kill_transactions] AS | |
IF OBJECT_ID('tempdb..#stats_ddl') IS NOT NULL | |
BEGIN; | |
DROP TABLE #stats_ddl; | |
END; | |
CREATE TABLE #stats_ddl | |
WITH |