forked from alexott/databricks-nutter-repos-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Code1.py
26 lines (19 loc) · 727 Bytes
/
Code1.py
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
# Databricks notebook source
import pyspark.sql.functions as F
import pyspark.sql.types as T
from pyspark.sql import DataFrame, SparkSession
# COMMAND ----------
def generate_data1(n=1000, name='my_cool_data'):
df = SparkSession.getActiveSession().range(0, n)
df.createOrReplaceTempView(name)
# COMMAND ----------
def upper_columns(df: DataFrame, cols: list) -> DataFrame:
new_cols = []
for field in df.schema.fields:
if field.dataType == T.StringType() and field.name in cols:
new_cols.append(F.upper(F.col(field.name)).alias(field.name))
else:
new_cols.append(F.col(field.name))
return df.select(*new_cols)
# COMMAND ----------
# add the comment