All Products
Search
Document Center

Realtime Compute for Apache Flink:PARSE_URL

Last Updated:Nov 21, 2024

Parses a specific part of a URL and returns the parsed value.

Syntax

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

Arguments

Argument

Data type

Description

urlStr

VARCHAR

The URL that you want to parse.

Note

If the value of urlStr is NULL, NULL is returned.

partToExtract

VARCHAR

The part that you want to parse from the URL. Valid values:

  • HOST

  • PATH

  • QUERY

  • REF

  • PROTOCOL

  • FILE

  • AUTHORITY

  • USERINFO

key

VARCHAR

The key whose value you want to extract. This argument is optional.

Example

  • Test data in the T1 table

    url1(VARCHAR)

    url2(VARCHAR)

    http://facebook.com/path/p1.php?query=1

    NULL

  • Test code

    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(url1, 'USERINFO') as var9,
           PARSE_URL(url2, 'QUERY') as var10
    FROM T1; 
  • Test result

    var1

    (VARCHAR)

    var2

    (VARCHAR)

    var3

    (VARCHAR)

    var4

    (VARCHAR)

    var5

    (VARCHAR)

    1

    query=1

    facebook.com

    /path/p1.php

    -

    var6

    (VARCHAR)

    var7

    (VARCHAR)

    var8

    (VARCHAR)

    var9

    (VARCHAR)

    var10

    (VARCHAR)

    http

    /path/p1.php?query=1

    facebook.com

    -

    -