Is there a way to parse XML tags in BigQuery Standard SQL?

后端 未结 1 1413
日久生厌
日久生厌 2020-12-20 07:14

I have read that it\'s a bad idea to parse XML/HTML using regular expressions. The alternative suggestion is to use an XML parser. Does one exist in the BigQuery Standard SQ

1条回答
  •  时光说笑
    2020-12-20 08:16

    Here is the documentation to how to use Javascript UDFs in BigQuery like Elliot has mentioned.

    https://cloud.google.com/bigquery/docs/reference/standard-sql/user-defined-functions

    I imagine the UDF might look something like

    CREATE TEMPORARY FUNCTION XML(x STRING)
    RETURNS STRING
      LANGUAGE js AS """
      var data = fromXML(x);
      return data.title;
    """
    OPTIONS(
    library="gs:///from-xml.min.js"
    );
    SELECT XML(a) FROM UNNEST(["Title of Page"]) as a
    

    Where from-xml.min.js is from this library and loaded into your gcs account

    0 讨论(0)
提交回复
热议问题