Skip to content

Commit

Permalink
feat: recognize syntax of BLOB and CLOB types.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashigeru committed Jan 23, 2025
1 parent 56b890e commit 66e629a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 6 deletions.
8 changes: 4 additions & 4 deletions include/mizugaki/ast/type/kind.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ enum class kind {
/**
* @brief character large object type.
*/
character_large_object, // FIXME: impl
character_large_object,

/**
* @brief bit string type.
Expand Down Expand Up @@ -75,7 +75,7 @@ enum class kind {
/**
* @brief binary large object type.
*/
binary_large_object, // FIXME: impl
binary_large_object,

/**
* @brief exact numeric type.
Expand Down Expand Up @@ -221,7 +221,7 @@ template<> struct type_of<kind, kind::character> : ::takatori::util::meta_type<c
/// @brief provides implementation type of kind::character_varying.
template<> struct type_of<kind, kind::character_varying> : ::takatori::util::meta_type<character_string> {};

/// @brief FIXME: provides implementation type of kind::character_large_object.
/// @brief provides implementation type of kind::character_large_object.
template<> struct type_of<kind, kind::character_large_object> : ::takatori::util::meta_type<simple> {};

/// @brief provides implementation type of kind::bit.
Expand All @@ -236,7 +236,7 @@ template<> struct type_of<kind, kind::octet> : ::takatori::util::meta_type<octet
/// @brief provides implementation type of kind::octet_varying.
template<> struct type_of<kind, kind::octet_varying> : ::takatori::util::meta_type<octet_string> {};

/// @brief FIXME: provides implementation type of kind::binary_large_object.
/// @brief provides implementation type of kind::binary_large_object.
template<> struct type_of<kind, kind::binary_large_object> : ::takatori::util::meta_type<simple> {};

/// @brief provides implementation type of kind::numeric.
Expand Down
2 changes: 2 additions & 0 deletions include/mizugaki/ast/type/simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class simple final : public type {
node_kind_type::double_precision,
node_kind_type::boolean,
node_kind_type::date,
node_kind_type::binary_large_object,
node_kind_type::character_large_object,
};

/**
Expand Down
19 changes: 17 additions & 2 deletions src/mizugaki/parser/sql_parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@
%token NOT "NOT"
%token NULL_ "NULL"
%token NUMERIC "NUMERIC"
// %token <ast::common::chars> OBJECT "OBJECT"
%token OBJECT "OBJECT"
%token OF "OF"
// %token <ast::common::chars> OFF "OFF"
%token OLD "OLD"
Expand Down Expand Up @@ -4088,7 +4088,22 @@ data_type_system
{
$$ = driver.node<ast::type::interval>(@$);
}
// FIXME: large object types
| BLOB
{
$$ = driver.node<ast::type::simple>(ast::type::kind::binary_large_object, @$);
}
| BINARY LARGE OBJECT
{
$$ = driver.node<ast::type::simple>(ast::type::kind::binary_large_object, @$);
}
| CLOB
{
$$ = driver.node<ast::type::simple>(ast::type::kind::character_large_object, @$);
}
| character_type_name LARGE OBJECT
{
$$ = driver.node<ast::type::simple>(ast::type::kind::character_large_object, @$);
}
;

data_type_composite
Expand Down
1 change: 1 addition & 0 deletions src/mizugaki/parser/sql_scanner.ll
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ UTF8_CHAR {ASCII}|{UTF8_2}{U}|{UTF8_3}{U}{U}|{UTF8_4}{U}{U}{U}
"NOT" { return parser_type::make_NOT(location()); }
"NULL" { return parser_type::make_NULL_(location()); }
"NUMERIC" { return parser_type::make_NUMERIC(location()); }
"OBJECT" { return parser_type::make_OBJECT(location()); }
"OF" { return parser_type::make_OF(location()); }
"OLD" { return parser_type::make_OLD(location()); }
"ON" { return parser_type::make_ON(location()); }
Expand Down
45 changes: 45 additions & 0 deletions test/mizugaki/parser/sql_parser_type_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,51 @@ TEST_F(sql_parser_type_test, DISABLED_interval_qualifier) {
}));
}

TEST_F(sql_parser_type_test, blob) {
auto result = parse("BLOB");
ASSERT_TRUE(result) << diagnostics(result);

EXPECT_EQ(extract(result), (type::simple {
type::kind::binary_large_object,
}));
}

TEST_F(sql_parser_type_test, binary_large_object) {
auto result = parse("BINARY LARGE OBJECT");
ASSERT_TRUE(result) << diagnostics(result);

EXPECT_EQ(extract(result), (type::simple {
type::kind::binary_large_object,
}));
}

TEST_F(sql_parser_type_test, clob) {
auto result = parse("CLOB");
ASSERT_TRUE(result) << diagnostics(result);

EXPECT_EQ(extract(result), (type::simple {
type::kind::character_large_object,
}));
}

TEST_F(sql_parser_type_test, character_large_object) {
auto result = parse("CHARACTER LARGE OBJECT");
ASSERT_TRUE(result) << diagnostics(result);

EXPECT_EQ(extract(result), (type::simple {
type::kind::character_large_object,
}));
}

TEST_F(sql_parser_type_test, char_large_object) {
auto result = parse("CHAR LARGE OBJECT");
ASSERT_TRUE(result) << diagnostics(result);

EXPECT_EQ(extract(result), (type::simple {
type::kind::character_large_object,
}));
}

TEST_F(sql_parser_type_test, row) {
auto result = parse("ROW (a int)");
ASSERT_TRUE(result) << diagnostics(result);
Expand Down

0 comments on commit 66e629a

Please sign in to comment.