Skip to content
Snippets Groups Projects
Commit cc33caf7 authored by Igor Kuznetsov's avatar Igor Kuznetsov
Browse files

feat: sync column info with tarantool box.execute format

parent 60a90000
No related branches found
No related tags found
1 merge request!1414sbroad import
......@@ -12,13 +12,14 @@ fasthash = "0.4.0"
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.8"
sqlparser = "0.11.0"
tarantool = { git = "https://sbroad-cargo-token:t-nZyqJVVuhGQv17BX6v@gitlab.com/picodata/picodata/tarantool-module.git", rev="8e388030"}
tarantool = { git = "https://sbroad-cargo-token:t-nZyqJVVuhGQv17BX6v@gitlab.com/picodata/picodata/tarantool-module.git", rev="6f6bc329"}
traversal = "0.1.2"
yaml-rust = "0.4.1"
[dev-dependencies]
pretty_assertions = "1.0.0"
itertools = "0.8.2"
rmp-serde = "0.14"
[lib]
crate-type = ["cdylib"]
......@@ -2,22 +2,26 @@
use std::collections::{HashMap, HashSet};
use serde::ser::{Serialize as SerSerialize, SerializeMap, Serializer};
use serde::{Deserialize, Serialize};
use tarantool::hlua::{self, LuaRead};
use crate::errors::QueryPlannerError;
use super::value::Value;
/// Supported column types.
#[derive(Serialize, Deserialize, PartialEq, Debug)]
#[derive(LuaRead, Serialize, Deserialize, PartialEq, Debug, Eq)]
pub enum Type {
Boolean,
Number,
String,
Integer,
Unsigned,
}
/// Relation column.
#[derive(Serialize, Deserialize, PartialEq, Debug)]
#[derive(LuaRead, Deserialize, PartialEq, Debug, Eq)]
pub struct Column {
/// Column name.
pub name: String,
......@@ -25,6 +29,26 @@ pub struct Column {
pub r#type: Type,
}
/// Msgpack serializer for column
impl SerSerialize for Column {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut map = serializer.serialize_map(Some(2))?;
map.serialize_entry("name", &self.name)?;
match &self.r#type {
Type::Boolean => map.serialize_entry("type", "boolean")?,
Type::Number => map.serialize_entry("type", "number")?,
Type::Integer => map.serialize_entry("type", "integer")?,
Type::Unsigned => map.serialize_entry("type", "unsigned")?,
Type::String => map.serialize_entry("type", "string")?,
}
map.end()
}
}
#[allow(dead_code)]
impl Column {
/// Column constructor.
......
use super::*;
use pretty_assertions::{assert_eq, assert_ne};
use std::fs;
use std::path::Path;
use pretty_assertions::{assert_eq, assert_ne};
use super::*;
#[test]
fn column() {
let a = Column {
......@@ -85,6 +87,8 @@ fn table_seg_serialized() {
Column::new("b", Type::Number),
Column::new("c", Type::String),
Column::new("d", Type::String),
Column::new("e", Type::Integer),
Column::new("f", Type::Unsigned),
],
&["a", "d"],
)
......@@ -157,3 +161,71 @@ fn table_seg_serialized_no_columns() {
QueryPlannerError::Serialization
);
}
#[test]
fn column_msgpack_serialize() {
let c = Column {
name: "name".into(),
r#type: Type::Boolean,
};
assert_eq!(
vec![
0x82, 0xA4, 0x6E, 0x61, 0x6D, 0x65, 0xA4, 0x6E, 0x61, 0x6D, 0x65, 0xA4, 0x74, 0x79,
0x70, 0x65, 0xA7, 0x62, 0x6F, 0x6F, 0x6C, 0x65, 0x61, 0x6E,
],
rmp_serde::to_vec(&c).unwrap()
);
let c = Column {
name: "name".into(),
r#type: Type::String,
};
assert_eq!(
vec![
0x82, 0xA4, 0x6E, 0x61, 0x6D, 0x65, 0xA4, 0x6E, 0x61, 0x6D, 0x65, 0xA4, 0x74, 0x79,
0x70, 0x65, 0xA6, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67
],
rmp_serde::to_vec(&c).unwrap()
);
let c = Column {
name: "name".into(),
r#type: Type::Integer,
};
assert_eq!(
vec![
0x82, 0xA4, 0x6E, 0x61, 0x6D, 0x65, 0xA4, 0x6E, 0x61, 0x6D, 0x65, 0xA4, 0x74, 0x79,
0x70, 0x65, 0xA7, 0x69, 0x6E, 0x74, 0x65, 0x67, 0x65, 0x72,
],
rmp_serde::to_vec(&c).unwrap()
);
let c = Column {
name: "name".into(),
r#type: Type::Unsigned,
};
assert_eq!(
vec![
0x82, 0xA4, 0x6E, 0x61, 0x6D, 0x65, 0xA4, 0x6E, 0x61, 0x6D, 0x65, 0xA4, 0x74, 0x79,
0x70, 0x65, 0xA8, 0x75, 0x6E, 0x73, 0x69, 0x67, 0x6E, 0x65, 0x64,
],
rmp_serde::to_vec(&c).unwrap()
);
let c = Column {
name: "name".into(),
r#type: Type::Number,
};
assert_eq!(
vec![
0x82, 0xA4, 0x6E, 0x61, 0x6D, 0x65, 0xA4, 0x6E, 0x61, 0x6D, 0x65, 0xA4, 0x74, 0x79,
0x70, 0x65, 0xA6, 0x6E, 0x75, 0x6D, 0x62, 0x65, 0x72,
],
rmp_serde::to_vec(&c).unwrap()
)
}
......@@ -8,6 +8,10 @@ Segment:
type: String
- name: d
type: String
- name: e
type: Integer
- name: f
type: Unsigned
name: t
key:
- 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment