Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Design how to convert chain node openrpc spec to streaming table definitions #61

Closed
Tracked by #53
imotai opened this issue Jun 29, 2022 · 0 comments · Fixed by #64
Closed
Tracked by #53

Design how to convert chain node openrpc spec to streaming table definitions #61

imotai opened this issue Jun 29, 2022 · 0 comments · Fixed by #64

Comments

@imotai
Copy link
Contributor

imotai commented Jun 29, 2022

Data Model

let‘s look at the method eth_getBlockByHash from etherum openrpc.json

name type
parentHash string
sha3Uncles string
miner string
stateRoot string
transactionsRoot string
receiptsRoot string
receiptsRoot string
transactions array
number string
... ...

Query Block

select timestamp, miner, number from block where number in (15044280);

this sql will call json rpc

call eth_getBlockByNumber(15044280)

do some process

select date(`timestamp`),  miner, number from block where number in (15044280);

Query Transaction in block

select * from Values (select block.transactions where number in (15044280));

use datafusion to query table against json

let ctx = SessionContext::new();
    let path = format!("{}/2.json", TEST_DATA_BASE);
    ctx.register_json("t1", &path, NdJsonReadOptions::default())
        .await
        .unwrap();

    let sql = "SELECT a, b FROM t1";
    let actual = execute_to_batches(&ctx, sql).await;
    let expected = vec![
        "+-----------------+------+",
        "| a               | b    |",
        "+-----------------+------+",
        "| 1               | 2    |",
        "| -10             | -3.5 |",
        "| 2               | 0.6  |",
        "| 1               | 2    |",
        "| 7               | -3.5 |",
        "| 1               | 0.6  |",
        "| 1               | 2    |",
        "| 5               | -3.5 |",
        "| 1               | 0.6  |",
        "| 1               | 2    |",
        "| 1               | -3.5 |",
        "| 100000000000000 | 0.6  |",
        "+-----------------+------+",
    ];

    assert_batches_eq!(expected, &actual);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant