OBS data source

Updated at:

An OBS data source allows you to read files. You can use this data source to retrieve files stored in OBS, parse the files, and synchronize the data to any destination data source. This topic describes the capabilities supported for OBS data synchronization in DataWorks.

Limits

An OBS data source supports the following data types.

Data type

Description

STRING

Text.

LONG

Integers.

BYTES

Byte arrays. The text read is converted to UTF-8-encoded byte arrays.

BOOL

Boolean values.

DOUBLE

Floating-point numbers.

DATE

Date and time values. The following date and time formats are supported:

  • YYYY-MM-dd HH:mm:ss

  • yyyy-MM-dd

  • HH:mm:ss

Create a data source

When you develop a data synchronization task, you must create a corresponding data source in DataWorks. For more information about the procedure, see Create and manage data sources. For detailed explanations of the configuration parameters, view the hints for the corresponding parameters in the configuration UI.

Develop a data synchronization task

For information about where to configure data synchronization tasks and the general configuration procedure, see the following configuration guides.

Configuration guides for single-table batch synchronization tasks

Appendix: Sample script and parameter descriptions

Configure a batch task in script mode

If you configure a batch task in script mode, you must specify the corresponding parameters in the task script in accordance with the standard script format requirements. For more information, see Configure a batch synchronization task in script mode. The following sections describe the data source parameter configurations in script mode.

Sample Reader script

{
  "type": "job",
  "version": "2.0",
  "steps": [
    {
      "stepType": "obs",
      "parameter": {
        "datasource": "",
        "object": ["f/z/1.csv"],
        "fileFormat": "csv",
        "encoding": "utf8/gbk/...",
        "fieldDelimiter": ",",
        "useMultiCharDelimiter": true,
        "lineDelimiter": "\n",
        "skipHeader": true,
        "compress": "zip/gzip",
        "column": [
          {
            "index": 0,
            "type": "long"
          },
          {
            "index": 1,
            "type": "boolean"
          },
          {
            "index": 2,
            "type": "double"
          },
          {
            "index": 3,
            "type": "string"
          },
          {
            "index": 4,
            "type": "date"
          }
        ]
      },
      "name": "Reader",
      "category": "reader"
    },
    {
      "stepType": "stream",
      "parameter": {},
      "name": "Writer",
      "category": "writer"
    }
  ],
  "setting": {
    "errorLimit": {
      "record": "0"
    },
    "speed": {
      "concurrent": 1
    }
  },
  "order": {
    "hops": [
      {
        "from": "Reader",
        "to": "Writer"
      }
    ]
  }
}

Reader script parameters

Parameter

Description

Required

Default value

datasource

The name of the data source. Script mode supports adding data sources. The value of this parameter must match the name of the added data source.

Yes

None

fileFormat

The type of the source file. Supported types: csv, text, parquet, and orc.

Yes

None

object

The file path. This parameter is used when fileFormat is set to csv or text.
Note
This parameter supports the * wildcard and can be configured as an array.
For example, if you want to synchronize the a/b/1.csv and a/b/2.csv files, you can set this parameter to a/b/*.csv.


Yes (required when fileFormat is set to csv or text)

None

column

The list of fields to read. type specifies the data type of the source data. index specifies the column in the text from which the current column is read, starting from 0. value specifies that the current type is a constant. Instead of reading data from the source file, the corresponding column is automatically generated based on the value of value.
By default, you can read all data as the String type by configuring "column": ["*"].
You can also specify column field information. For example: "column": [{"type": "long", "index": 0}, {"type": "string", "value": "alibaba"}].
Note
For the column information that you specify, type is required, and you must specify either index or value.



Yes

All data is read as the STRING type.

fieldDelimiter

The field delimiter used to read data.
Note

  • When OBS Reader reads data, you must specify a field delimiter. If you do not specify a delimiter, the default is a comma (,). The configuration UI also uses a comma (,) by default.

  • If the delimiter is invisible, specify its Unicode encoding. For example: \u001b or \u007c.

Yes

,

lineDelimiter

The line delimiter used to read data.
Note
This parameter takes effect when fileFormat is set to text.

No

None

compress

The text compression type. This parameter is left unspecified by default, which means no compression. Supported compression types: gzip, bzip2, and zip.

No

No compression

encoding

The encoding used to read files.

No

utf-8

nullFormat

A standard string cannot define null (a null pointer) in a text file. The data synchronization system provides nullFormat to specify which strings represent null. For example:

  • Setting nullFormat:"null" is equivalent to specifying visible characters. If the source data is null, the data synchronization system treats it as a null field.

  • Setting nullFormat:"\u0001" is equivalent to specifying an invisible character. If the source data is the string "\u0001", the data synchronization system treats it as a null field.

  • Omitting the "nullFormat" parameter is equivalent to leaving it unconfigured. The source data is written directly to the destination as is, without any conversion.

No

None

skipHeader

For CSV files, skipHeader specifies whether to read the header content.

  • True: Reads the header content when synchronizing the data source.

  • False: Does not read the header content when synchronizing the data source.

Note
skipHeader is not supported in compressed file mode.

No

false

parquetSchema

Configure this parameter when reading OBS data in Parquet file format. This parameter takes effect if and only if fileFormat is set to parquet and describes the types stored in parquet. After you specify parquetSchema, make sure that the entire configuration complies with JSON syntax.
Format: message MessageType name { required status, data type, column name; ...; }
The configuration format of parquetSchema is described as follows:

  • MessageType name: Specify a name.

  • Required status: required indicates that the value cannot be null, and optional indicates that the value can be null. We recommend that you use optional for all fields.

  • Data type: Parquet files support BOOLEAN, Int32, Int64, Int96, FLOAT, DOUBLE, BINARY (use BINARY for strings), and fixed_len_byte_array.

  • The column definition on each line must end with a semicolon, including the last line.

The following example shows a configuration:
"parquetSchema": "message m { optional int32 minute_id; optional int32 dsp_id; optional int32 adx_pid; optional int64 req; optional int64 res; optional int64 suc; optional int64 imp; optional double revenue; }"

No

None

csvReaderConfig

Parameters for reading CSV files are configured as a Map. CSV files are read by using CsvReader. If you do not configure this parameter, the default values are used.

No

None