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

[#40] Consistent column order for MBCUSTOMQUERY #50

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

daenamkim
Copy link
Collaborator

Resolves #40

Result columns will be ordered based on what input index is set for MBCUSTOMQUERY

Copy link
Collaborator

@shoenseiwaso shoenseiwaso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just read through the code briefly for now. I think this is dependent on #35? I'll review that next!

src/Code.js Outdated
@@ -469,7 +469,12 @@ function MBCUSTOMQUERY(events, groupBy, orderBy, limit, offset) {

// turn the array of objects into a flat array
const objArr = results.result.rows;
return objectArrayToArray(objArr);
const headersPreset = Array(payload.events[0].select.length);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could events[0] ever be null?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it could be null but throw new Error() will happen before

function buildCustomQuery(events, groupBy, orderBy, limit, offset) {
const query = {
events: [],
};
if (groupBy && groupBy !== '') {
query.groupBy = groupBy;
}
if (orderBy && orderBy !== '') {
query.orderBy = orderBy;
}
// parse and validate header row
if (events.length < 1) {
throw new Error(`Expecting a header row followed by one or more data rows, found ${events.length} rows total`);
}

@daenamkim
Copy link
Collaborator Author

daenamkim commented Dec 11, 2020

Just read through the code briefly for now. I think this is dependent on #35? I'll review that next!

I think this is not dependent on it because this PR is for selects part not filters

@shoenseiwaso shoenseiwaso self-assigned this Dec 13, 2020
Copy link
Collaborator

@shoenseiwaso shoenseiwaso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there! Some adjustment needed per my comment below.

src/Code.js Outdated
return objectArrayToArray(objArr);
const headersPreset = Array(payload.events[0].select.length);
// eslint-disable-next-line no-restricted-syntax, guard-for-in
for (const s of payload.events[0].select) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that it's not a requirement that each event row is the same event, nor that it has the same aliases. Therefore, I don't think we can just use events[0]:

For example, this is valid:
image

Which generates the following query:

{
    "events": [
        {
            "eventName": "Transfer",
            "select": [
                {
                    "alias": "abc",
                    "inputIndex": 0,
                    "type": "input"
                },
                {
                    "alias": "ghi",
                    "inputIndex": 2,
                    "type": "input"
                }
            ],
            "filter": {
                "rule": "and",
                "children": [
                    {
                        "operator": "equal",
                        "value": "autotoken",
                        "fieldType": "contract_address_label"
                    }
                ]
            }
        },
        {
            "eventName": "Mint",
            "select": [
                {
                    "alias": "def",
                    "inputIndex": 1,
                    "type": "input"
                },
                {
                    "alias": "jkl",
                    "inputIndex": 2,
                    "type": "input"
                }
            ],
            "filter": {
                "rule": "and",
                "children": [
                    {
                        "operator": "equal",
                        "value": "autotoken",
                        "fieldType": "contract_address_label"
                    }
                ]
            }
        }
    ]
}

With the following result:

{
    "status": 200,
    "message": "success",
    "result": {
        "rows": [
            {
                "abc": null,
                "def": "0xf9450d254a66ab06b30cfa9c6e7ae1b7598c7172",
                "ghi": null,
                "jkl": "100000000000"
            },
            {
                "abc": "0x0000000000000000000000000000000000000000",
                "def": null,
                "ghi": "100000000000",
                "jkl": null
            },
            {
                "abc": "0xf9450d254a66ab06b30cfa9c6e7ae1b7598c7172",
                "def": null,
                "ghi": "10000000000",
                "jkl": null
            },
            {
                "abc": "0xf9450d254a66ab06b30cfa9c6e7ae1b7598c7172",
                "def": null,
                "ghi": "1000000000",
                "jkl": null
            },
            {
                "abc": null,
                "def": "0xf9450d254a66ab06b30cfa9c6e7ae1b7598c7172",
                "ghi": null,
                "jkl": "100000000000"
            },
            {
                "abc": "0x0000000000000000000000000000000000000000",
                "def": null,
                "ghi": "100000000000",
                "jkl": null
            },
            {
                "abc": "0xf9450d254a66ab06b30cfa9c6e7ae1b7598c7172",
                "def": null,
                "ghi": "2000000000",
                "jkl": null
            },
            {
                "abc": null,
                "def": "0xf9450d254a66ab06b30cfa9c6e7ae1b7598c7172",
                "ghi": null,
                "jkl": "870000000"
            },
            {
                "abc": "0x0000000000000000000000000000000000000000",
                "def": null,
                "ghi": "870000000",
                "jkl": null
            },
            {
                "abc": "0xf9450d254a66ab06b30cfa9c6e7ae1b7598c7172",
                "def": null,
                "ghi": "100",
                "jkl": null
            }
        ]
    }
}

image

I tested this PR by merging #35 into this branch, and indeed, the output is broken:

image

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 this pull request may close these issues.

MBCUSTOMQUERY results should have a consistent column order by selector index not alias
2 participants