Use MaxFrame in DataWorks

更新时间:
复制 MD 格式

MaxFrame is built into DataWorks PyODPS 3 nodes, so you can directly develop and run MaxFrame jobs.

Prerequisites

Create a MaxCompute data source and associate it with your target DataWorks workspace. For instructions, see Associate a data source or a cluster with DataStudio.

Use MaxFrame

  1. Create a PyODPS 3 node.

    Go to the Data Development page in DataWorks to create a PyODPS 3 node. For instructions, see Develop a PyODPS 3 task.

  2. Create a MaxFrame session.

    PyODPS 3 includes built-in MaxCompute user and project information, so you can create a MaxFrame session directly. Example:

    import maxframe.dataframe as md
    from maxframe import new_session
    from maxframe.config import options
    options.sql.enable_mcqa = False
    
    table = o.create_table("test_source_table", "a string, b bigint", if_not_exists=True)
    with table.open_writer() as writer:
        writer.write([
            ["value1", 0],
            ["value2", 1],
        ])
    
    # Create a MaxFrame session.
    session = new_session(o)
    
    df = md.read_odps_table("test_source_table",index_col="b")
    df["a"] = "prefix_" + df["a"]
    
    # Print the DataFrame data.
    print(df.execute().fetch())
    
    # Write the MaxFrame DataFrame data to a MaxCompute table.
    md.to_odps_table(df, "test_prefix_source_table").execute()
    
    # Destroy the MaxFrame session.
    session.destroy()
    

Result validation

After running the Python code, query the sink table data. If the result matches expectations, MaxFrame is installed successfully and connected to the MaxCompute cluster.

  1. Running the Python code returns the following result:

    b           a
    0  prefix_value1
    1  prefix_value2
  2. In your target MaxCompute project, run the following SQL to query data in the test_prefix_source_table table.

    SELECT * FROM test_prefix_source_table;

    The returned result is:

    +------------+------------+
    | b          | a          |
    +------------+------------+
    | 0          | prefix_value1 |
    | 1          | prefix_value2 |
    +------------+------------+