Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

U-SQL Python Hello World

License

Notifications You must be signed in to change notification settings

Azure-Samples/usql-python-hello-world

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

services platforms author
data-lake-analytics
python
saveenr

U-SQL: Python Hello World

Case 1: no transformation of partitions

REFERENCE ASSEMBLY [ExtPython];

DECLARE @myScript = @"

def usqlml_main(df):
    return df
";

@t  = 
    SELECT * FROM 
        (VALUES
            ("key1",100),
            ("key1",101),
            ("key2",200),
            ("key3",202)
        ) AS 
              D( partitionkey, value );

@m  =
    REDUCE @t ON partitionkey
    PRODUCE partitionkey string, value string
    USING new Extension.Python.Reducer(pyScript:@myScript);


OUTPUT @m
  TO "/output.csv"
  USING Outputters.Csv();

Case 2: Transforming the partitions

REFERENCE ASSEMBLY [ExtPython];

DECLARE @myScript = @"
def get_mentions(tweet):
    return ';'.join( ( w[1:] for w in tweet.split() if w[0]=='@' ) )

def usqlml_main(df):
    del df['time']
    del df['author']
    df['mentions'] = df.tweet.apply(get_mentions)
    del df['tweet']
    return df
";

@t  = 
    SELECT * FROM 
        (VALUES
            ("D1","T1","A1","@foo Hello World @bar"),
            ("D2","T2","A2","@baz Hello World @beer")
        ) AS 
              D( date, time, author, tweet );

@m  =
    REDUCE @t ON date
    PRODUCE date string, mentions string
    USING new Extension.Python.Reducer(pyScript:@myScript);


OUTPUT @m
  TO "/tweetmentions.csv"
  USING Outputters.Csv();

About

U-SQL Python Hello World

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published