This topic describes how to use the string function PARSE_URL in Realtime Compute.

Syntax

VARCHAR PARSE_URL(VARCHAR urlStr, VARCHAR partToExtract [, VARCHAR key])

Input parameters

Parameter Data type Description
urlStr VARCHAR A URL string.
partToExtract VARCHAR The part to be parsed from the specified URL. Valid values:
  • HOST
  • PATH
  • QUERY
  • REF
  • PROTOCOL
  • FILE
  • AUTHORITY
  • USERINFO
key VARCHAR The name of the key whose value you want to extract. This parameter is optional.

Description

Parses a URL and returns the parsed value of the specified part of the URL. If the value of the urlStr parameter is null, null is returned.

Example

  • Test data
    url1 (VARCHAR) nullstr (VARCHAR)
    http://facebook.com/path/p1.php?query=1 null
  • Test statements
    SELECT PARSE_URL(url1, 'QUERY', 'query') as var1,
           PARSE_URL(url1, 'QUERY') as var2,
           PARSE_URL(url1, 'HOST') as var3,
           PARSE_URL(url1, 'PATH') as var4,
           PARSE_URL(url1, 'REF') as var5,
           PARSE_URL(url1, 'PROTOCOL') as var6,
           PARSE_URL(url1, 'FILE') as var7,
           PARSE_URL(url1, 'AUTHORITY') as var8,
           PARSE_URL(nullstr, 'QUERY') as var9,
           PARSE_URL(url1, 'USERINFO') as var10,
           PARSE_URL(nullstr, 'QUERY', 'query') as var11
    FROM T1; 
  • Test results
    var1 (VARCHAR) var2 (VARCHAR) var3 (VARCHAR) var4 (VARCHAR) var5 (VARCHAR) var6 (VARCHAR) var7 (VARCHAR) var8 (VARCHAR) var9 (VARCHAR) var10 (VARCHAR) var11 (VARCHAR)
    1 query=1 facebook.com /path/p1.php null http /path/p1.php? query=1 facebook.com null null null