# Blockchain components · Big data analysis with Chromia and PySpark · Learn Chromia

> The pagination utility comes from the FT4 library, so you need to import it first.

Source: https://chromia.com/learn/big-data/blockchain-side-description/

Big data analysis with Chromia and PySparkLesson 5 of 6

1. [01Analyzing Chromia blockchain data with PySpark](https://chromia.com/learn/big-data/introduction/)
2. [02Set up your project](https://chromia.com/learn/big-data/setup/)
3. [03Prepare the project](https://chromia.com/learn/big-data/project-launch/)
4. [04Run the project](https://chromia.com/learn/big-data/project-run/)
5. [05Blockchain components](https://chromia.com/learn/big-data/blockchain-side-description/)
6. [06Python components](https://chromia.com/learn/big-data/python-side-description/)

[Learn](https://chromia.com/learn/)[Big data analysis with Chromia and PySpark](https://chromia.com/learn/big-data/)

05 / 06Intermediate

# Blockchain components

## Navigate to the blockchain folder

shell

```nolines
cd rell/src
```

## The key components of the blockchain dapp

The pagination utility comes from the [FT4 library](https://docs.chromia.com/build/ft4/setup/ft4-setup/), so you need to import it first.

./chromia.yml

```
libs:
  ft4:
    registry: https://gitlab.com/chromaway/ft4-lib.git
    path: rell/src/lib/ft4
    tagOrBranch: v1.2.0r
    rid: x"E96915FD7C9A5DD4E183D86F4A5B4BB5083A7CC1EDEB1465EDFFC926E67C93F6"
    insecure: false
```

You store the data to be analyzed in an [entity](https://docs.chromia.com/rell/core-concepts#entity-definitions) called `product`. Its structure works much like a table in a relational database.

./main.rell

```
entity product {
    name: text;
    description: text;
    quantity: integer;
    price: integer;
}
```

To populate the data, you use an [operation](https://docs.chromia.com/rell/core-concepts#operations) called `seed_data`, which builds a list of products. It creates all the entities in a single batch with the statement `create product (batch);`.

./main.rell

```
operation seed_data() {
    // 100 bytes
    val name = "UltraPure Hydro Flask ProMax: Advanced Insulated Stainless Steel Bottle for Active and Everyday Use.";
    // 500 bytes
    val description = "Introducing the EcoSmart Water Bottle – your ultimate hydration companion! Made from premium, BPA-free materials, this bottle is designed for both functionality and style. With double-wall insulation, it keeps your beverages icy cold for up to 24 hours or piping hot for up to 12 hours. Its sleek, ergonomic design fits perfectly in your hand or cup holder. Featuring a leak-proof lid and a wide  mouth for easy cleaning or adding ice cubes, it’s perfect for gym sessions, hikes, or daily  commutes. Stay refreshed and eco-friendly with EcoSmart!";
    // in total a size of 1 object is going to be 616 bytes

    val batch_amount = 10; // amount of batches created
    val batch_size = 10000; // the batch will have this number of entities to be created as a batch

    // total data size can be calculated 
    // total_size = batch_amount * batch_size * object_size
    // the  total size can be tuned with changing any parameter listed above.

    var batch = list<struct<product>>();
    for (x in range(batch_amount)) {
        val shift_index = x * batch_size;
        for (y in range(batch_size)) {
            batch.add(
                struct<product>(
                    name = name + shift_index + y,
                    description = description,
                    quantity = shift_index + y,
                    price = shift_index + y
                )
            );
        }
        create product ( batch );
        batch.clear();
        print("saved", x);      
    }
}
```

To read the products back from the node one page at a time, you call the [query](https://docs.chromia.com/rell/core-concepts#queries) `get_products_paginated`. It relies on the cursor-based pagination provided by FT4.

./main.rell

```
 query get_products_paginated(page_size: integer?, page_cursor: text?): paginator.paged_result {
    val before_rowid = paginator.before_rowid(page_cursor);

    val paginated_result = product @* {
        .rowid > (before_rowid ?: rowid(0))
    } (
        paginator.pagination_result(
            data = map_product($).to_gtv_pretty(),
            rowid = .rowid
        )
    ) limit paginator.fetch_data_size(page_size);

    return paginator.make_page(paginated_result, page_size);
}
```

Data model

code

```
product {
    name: text;
    description: text;
    quantity: integer;
    price: integer;
}
```

Written for this site from Chromia’s public course. Code samples are the course’s own.

[← Previous**Run the project**](https://chromia.com/learn/big-data/project-run/)[Next →**Python components**](https://chromia.com/learn/big-data/python-side-description/)

On this page

* [Navigate to the blockchain folder](#navigate-to-the-blockchain-folder)
* [The key components of the blockchain dapp](#the-key-components-of-the-blockchain-dapp)
