Repository navigation
Expand file tree
/
Copy pathbasic_analysis.py
More file actions
63 lines (45 loc) · 1.7 KB
/
Copy pathbasic_analysis.py
File metadata and controls
63 lines (45 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
Basic sparkwise usage example for Microsoft Fabric.
This script demonstrates how to use sparkwise to analyze a Spark workload
and get optimization recommendations.
"""
from pyspark.sql import SparkSession
from sparkwise import diagnose, ask
# Initialize Spark session (or use existing notebookutils session in Fabric)
spark = SparkSession.builder \
.appName("sparkwise Example") \
.getOrCreate()
# Example: Read some data
df = spark.read.parquet("/lakehouse/default/Files/sample_data.parquet")
# Perform some transformations
result = df.groupBy("category").agg({"sales": "sum"})
# Write results
result.write.mode("overwrite").parquet("/lakehouse/default/Files/output.parquet")
# ========================================
# Run sparkwise Analysis
# ========================================
print("\n" + "="*70)
print("sparkwise ANALYSIS")
print("="*70 + "\n")
# Option 1: Analyze with DataFrame for deep inspection
diagnose.analyze(result)
# Option 2: Quick health check (faster)
# diagnose.quick_check()
# Option 3: Analyze last run without DataFrame
# diagnose.analyze_last_run()
# ========================================
# Ask Questions About Configurations
# ========================================
print("\n" + "="*70)
print("CONFIGURATION Q&A")
print("="*70 + "\n")
# Ask about a specific configuration
ask.config("spark.sql.shuffle.partitions")
# Search for configurations by keyword
ask.search("adaptive")
# ========================================
# Export Results (Optional)
# ========================================
# Export analysis to JSON file
# diagnose.analyze(export_path="/lakehouse/default/Files/sparkwise_report.json")
print("\nAnalysis complete! Check the output above for recommendations.")