UUID as a attribute type

main
Ziyang Hu 2 years ago
parent 6f567f089a
commit ca0d311a98

@ -23,16 +23,10 @@
<cargoProject FILE="$PROJECT_DIR$/Cargo.toml" />
</component>
<component name="ChangeListManager">
<list default="true" id="fb7002fa-47b1-45d9-bc6d-711b16e752b3" name="Changes" comment="transactions are hard">
<list default="true" id="fb7002fa-47b1-45d9-bc6d-711b16e752b3" name="Changes" comment="UUID as a DataValue">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Cargo.toml" beforeDir="false" afterPath="$PROJECT_DIR$/Cargo.toml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docs/source/datatypes.rst" beforeDir="false" afterPath="$PROJECT_DIR$/docs/source/datatypes.rst" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docs/source/functions.rst" beforeDir="false" afterPath="$PROJECT_DIR$/docs/source/functions.rst" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/data/expr.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/data/expr.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/data/functions.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/data/functions.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/data/json.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/data/json.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/data/tests/functions.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/data/tests/functions.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/data/value.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/data/value.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/data/attr.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/data/attr.rs" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -176,7 +170,7 @@
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1663161524540</updated>
<workItem from="1663161527741" duration="26111000" />
<workItem from="1663161527741" duration="26450000" />
</task>
<task id="LOCAL-00001" summary="regenerate idea files">
<created>1663161616722</created>
@ -220,7 +214,14 @@
<option name="project" value="LOCAL" />
<updated>1663233714452</updated>
</task>
<option name="localTasksCounter" value="7" />
<task id="LOCAL-00007" summary="UUID as a DataValue">
<created>1663240364425</created>
<option name="number" value="00007" />
<option name="presentableId" value="LOCAL-00007" />
<option name="project" value="LOCAL" />
<updated>1663240364425</updated>
</task>
<option name="localTasksCounter" value="8" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -244,6 +245,7 @@
<MESSAGE value="reintroduce bloom filter settings" />
<MESSAGE value="manifest file" />
<MESSAGE value="transactions are hard" />
<option name="LAST_COMMIT_MESSAGE" value="transactions are hard" />
<MESSAGE value="UUID as a DataValue" />
<option name="LAST_COMMIT_MESSAGE" value="UUID as a DataValue" />
</component>
</project>

@ -61,15 +61,15 @@ Schema types
In schema definition, the required type for a value can be specified by any of the following *schema-types*
* ``Ref``
* ``Component``
* ``Int``
* ``Float``
* ``Bool``
* ``String``
* ``Bytes``
* ``List``
* ``Uuid``
When retrieving triples' values, the schema-types ``Ref``, ``Component``, and ``Int`` are all represented by the value-type ``Number`` (actually ``Int``). The entity (the subject of the triple) is always a ``Ref``, always represented by a ``Number`` (``Int``).
When retrieving triples' values, the schema-type ``Ref``, is represented by the type ``Uuid``. The entity (the subject of the triple) is always a ``Ref``, always represented by a ``Uuid``.
Note the absence of the ``Null`` type in schema-types.

@ -2,7 +2,7 @@ use std::collections::BTreeMap;
use std::fmt::{Display, Formatter};
use log::error;
use miette::{ensure, Diagnostic, Result};
use miette::{Diagnostic, ensure, Result};
use rmp_serde::Serializer;
use serde::Serialize;
use smallvec::SmallVec;
@ -21,15 +21,15 @@ use crate::transact::triple::EntityNotFound;
#[repr(u8)]
#[derive(
Copy,
Clone,
PartialEq,
Ord,
PartialOrd,
Eq,
Debug,
serde_derive::Deserialize,
serde_derive::Serialize,
Copy,
Clone,
PartialEq,
Ord,
PartialOrd,
Eq,
Debug,
serde_derive::Deserialize,
serde_derive::Serialize,
)]
pub(crate) enum AttributeCardinality {
One = 1,
@ -56,15 +56,15 @@ impl Display for AttributeCardinality {
#[repr(u8)]
#[derive(
Copy,
Clone,
PartialEq,
Ord,
PartialOrd,
Eq,
Debug,
serde_derive::Deserialize,
serde_derive::Serialize,
Copy,
Clone,
PartialEq,
Ord,
PartialOrd,
Eq,
Debug,
serde_derive::Deserialize,
serde_derive::Serialize,
)]
pub(crate) enum AttributeTyping {
Ref = 1,
@ -75,6 +75,7 @@ pub(crate) enum AttributeTyping {
String = 6,
Bytes = 9,
List = 10,
Uuid = 11,
}
impl AttributeTyping {
@ -93,6 +94,7 @@ impl Display for AttributeTyping {
AttributeTyping::String => write!(f, "string"),
AttributeTyping::Bytes => write!(f, "bytes"),
AttributeTyping::List => write!(f, "list"),
AttributeTyping::Uuid => write!(f, "uuid")
}
}
}
@ -144,13 +146,27 @@ impl AttributeTyping {
Err(val)
}
}
AttributeTyping::Uuid => {
match val {
v @ DataValue::Uuid(_) => Ok(v),
DataValue::Str(s) => {
match uuid::Uuid::try_parse(&s) {
Ok(id) => {
Ok(DataValue::uuid(id))
}
Err(_) => Err(DataValue::Str(s))
}
}
v => Err(v)
}
}
}
}
}
#[repr(u8)]
#[derive(
Clone, PartialEq, Ord, PartialOrd, Eq, Debug, serde_derive::Deserialize, serde_derive::Serialize,
Clone, PartialEq, Ord, PartialOrd, Eq, Debug, serde_derive::Deserialize, serde_derive::Serialize,
)]
pub(crate) enum AttributeIndex {
None = 0,
@ -178,7 +194,7 @@ impl Display for AttributeIndex {
}
#[derive(
Clone, PartialEq, Ord, PartialOrd, Eq, Debug, serde_derive::Deserialize, serde_derive::Serialize,
Clone, PartialEq, Ord, PartialOrd, Eq, Debug, serde_derive::Deserialize, serde_derive::Serialize,
)]
pub(crate) struct Attribute {
pub(crate) id: AttrId,
@ -242,7 +258,7 @@ impl Attribute {
#[error("Cannot find triple with temp ID '{temp_id}'")]
#[diagnostic(code(eval::temp_id_not_found))]
#[diagnostic(help(
"As the attribute {attr_name} is of type 'ref', \
"As the attribute {attr_name} is of type 'ref', \
the given value is interpreted as a temp id, \
but it cannot be found in the input triples."
))]
@ -319,7 +335,7 @@ impl Attribute {
typing: self.val_type,
attr_name: self.name.to_string(),
}
.into()
.into()
})
}
}

Loading…
Cancel
Save