1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use {
    super::{ExprNode, IndexItemNode, QueryNode, SelectNode},
    crate::ast::Dictionary,
};

#[derive(Clone, Debug)]
pub enum TableType<'a> {
    Table,
    Series(ExprNode<'a>),
    Dictionary(Dictionary),
    Derived {
        subquery: Box<QueryNode<'a>>,
        alias: String,
    },
}

#[derive(Clone, Debug)]
pub struct TableFactorNode<'a> {
    pub table_name: String,
    pub table_type: TableType<'a>,
    pub table_alias: Option<String>,
    pub index: Option<IndexItemNode<'a>>,
}

impl<'a> TableFactorNode<'a> {
    pub fn select(self) -> SelectNode<'a> {
        SelectNode::new(self)
    }
}

pub fn glue_objects() -> TableFactorNode<'static> {
    TableFactorNode {
        table_name: "GLUE_OBJECTS".to_owned(),
        table_type: TableType::Dictionary(Dictionary::GlueObjects),
        table_alias: None,
        index: None,
    }
}

pub fn glue_tables() -> TableFactorNode<'static> {
    TableFactorNode {
        table_name: "GLUE_TABLES".to_owned(),
        table_type: TableType::Dictionary(Dictionary::GlueTables),
        table_alias: None,
        index: None,
    }
}

pub fn glue_indexes() -> TableFactorNode<'static> {
    TableFactorNode {
        table_name: "GLUE_INDEXES".to_owned(),
        table_type: TableType::Dictionary(Dictionary::GlueIndexes),
        table_alias: None,
        index: None,
    }
}

pub fn glue_table_columns() -> TableFactorNode<'static> {
    TableFactorNode {
        table_name: "GLUE_TABLE_COLUMNS".to_owned(),
        table_type: TableType::Dictionary(Dictionary::GlueTableColumns),
        table_alias: None,
        index: None,
    }
}

pub fn series<'a, T: Into<ExprNode<'a>>>(args: T) -> TableFactorNode<'a> {
    TableFactorNode {
        table_name: "SERIES".to_owned(),
        table_type: TableType::Series(args.into()),
        table_alias: None,
        index: None,
    }
}