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

Allow using Bytes for ID and switch block explorer to that #1445

Closed
wants to merge 10 commits into from

Conversation

lutter
Copy link
Collaborator

@lutter lutter commented Jan 12, 2020

Map between strings that represent bytes and bytea in the database; the difference between subgraphs that use Bytes for ID and those that use String is transparent to subgraph users. The only exception is that when an entity is stored with an id 0xdeadbeef it will be returned as the string deadbeef stripping the 0x prefix.

Currently, this is only used for network indexing; all user-supplied subgraphs still use String as their ID and there is no way for users to switch to Bytes.

Fixes #1414

@lutter
Copy link
Collaborator Author

lutter commented Jan 13, 2020

Rebased to latest master

lutter added 10 commits January 14, 2020 09:02
The correct IdType is closely tied to the subgraph and its schema -
ultimately, we need the user to tell us whether their subgraph is suitable
for using IdType::Bytes.

This change only puts the plumbing in place to do so; we still use
IdType::String for all subgraphs.
The metadata subgraph has two tables: entities and entity_history. The
latter has a column `id` of type `integer`, and we can therefore not use
information_schema to determine whether the subgraph uses `String` or
`Bytes` for the primary key
For JSONB storage, we have one table with a `text` id, and one with an
`int` id; depending on which one we saw first, we might get
confused. Instead, special-case JSONB storage and report that it uses
`IdType::String`
@lutter
Copy link
Collaborator Author

lutter commented Jan 14, 2020

Rebased to latest master

server/http/src/request.rs Show resolved Hide resolved
@@ -180,6 +180,18 @@ mod public {
state -> crate::entities::public::DeploymentSchemaStateMapping,
}
}

// Access to the bits of the information_schema we care about. It conists
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: conists -> consists

"bytea" => IdType::Bytes,
_ => {
return Err(StoreError::Unknown(format_err!(
"unsupported type `{}` for primary key column in table {} in schema {}(`{}`)",
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we put `` around the table {} placeholder too?

store/postgres/src/entities.rs Show resolved Hide resolved
pub enum IdType {
String,
#[allow(dead_code)]
Bytes,
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting, I didn't know you had already prepared this. 😉

store/postgres/src/relational.rs Show resolved Hide resolved
Comment on lines +231 to +232
let bytes = scalar::Bytes::from_str(&s)
.map_err(|e| DieselError::SerializationError(Box::new(e)))?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this identical to the new str_as_bytes helper?

scrubbed
}

macro_rules! assert_entity_eq {
Copy link
Contributor

Choose a reason for hiding this comment

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

I have nothing against macros, but this to me looks like it could also just be a regular function; unless I'm missing something?

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.

Allow using Bytes for ID and switch block explorer to that
2 participants