6
6
//
7
7
// Identification: src/common/internal_types.cpp
8
8
//
9
- // Copyright (c) 2015-2017 , Carnegie Mellon University Database Group
9
+ // Copyright (c) 2015-2018 , Carnegie Mellon University Database Group
10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
18
18
#include " common/internal_types.h"
19
19
#include " common/logger.h"
20
20
#include " common/macros.h"
21
- #include " type/value_factory.h"
22
21
#include " parser/sql_statement.h"
23
22
#include " parser/statements.h"
24
23
#include " util/string_util.h"
@@ -529,101 +528,152 @@ std::ostream &operator<<(std::ostream &os, const StatementType &type) {
529
528
// QueryType - String Utilities
530
529
// ===--------------------------------------------------------------------===//
531
530
std::string QueryTypeToString (QueryType query_type) {
532
- switch (query_type) {
533
- case QueryType::QUERY_BEGIN:return " BEGIN" ;
534
- case QueryType::QUERY_COMMIT:return " COMMIT" ;
535
- case QueryType::QUERY_ROLLBACK:return " ROLLBACK" ;
536
- case QueryType::QUERY_CREATE_DB:return " CREATE DATABASE" ;
537
- case QueryType::QUERY_CREATE_INDEX: return " CREATE INDEX" ;
538
- case QueryType::QUERY_CREATE_TABLE: return " CREATE TABLE" ;
539
- case QueryType::QUERY_CREATE_TRIGGER: return " CREATE TRIGGER" ;
540
- case QueryType::QUERY_CREATE_SCHEMA: return " CREATE SCHEMA" ;
541
- case QueryType::QUERY_CREATE_VIEW: return " CREATE VIEW" ;
542
- case QueryType::QUERY_DROP:return " DROP" ;
543
- case QueryType::QUERY_INSERT:return " INSERT" ;
544
- case QueryType::QUERY_SET: return " SET" ;
545
- case QueryType::QUERY_SHOW: return " SHOW" ;
546
- case QueryType::QUERY_UPDATE: return " UPDATE" ;
547
- case QueryType::QUERY_ALTER: return " ALTER" ;
548
- case QueryType::QUERY_DELETE: return " DELETE" ;
549
- case QueryType::QUERY_COPY: return " COPY" ;
550
- case QueryType::QUERY_ANALYZE: return " ANALYZE" ;
551
- case QueryType::QUERY_RENAME: return " RENAME" ;
552
- case QueryType::QUERY_PREPARE: return " PREPARE" ;
553
- case QueryType::QUERY_EXECUTE: return " EXECUTE" ;
554
- case QueryType::QUERY_SELECT: return " SELECT" ;
555
- case QueryType::QUERY_OTHER: default : return " OTHER" ;
531
+ switch (query_type) {
532
+ case QueryType::QUERY_BEGIN:
533
+ return " BEGIN" ;
534
+ case QueryType::QUERY_COMMIT:
535
+ return " COMMIT" ;
536
+ case QueryType::QUERY_ROLLBACK:
537
+ return " ROLLBACK" ;
538
+ case QueryType::QUERY_CREATE_DB:
539
+ return " CREATE DATABASE" ;
540
+ case QueryType::QUERY_CREATE_INDEX:
541
+ return " CREATE INDEX" ;
542
+ case QueryType::QUERY_CREATE_TABLE:
543
+ return " CREATE TABLE" ;
544
+ case QueryType::QUERY_CREATE_TRIGGER:
545
+ return " CREATE TRIGGER" ;
546
+ case QueryType::QUERY_CREATE_SCHEMA:
547
+ return " CREATE SCHEMA" ;
548
+ case QueryType::QUERY_CREATE_VIEW:
549
+ return " CREATE VIEW" ;
550
+ case QueryType::QUERY_DROP:
551
+ return " DROP" ;
552
+ case QueryType::QUERY_INSERT:
553
+ return " INSERT" ;
554
+ case QueryType::QUERY_SET:
555
+ return " SET" ;
556
+ case QueryType::QUERY_SHOW:
557
+ return " SHOW" ;
558
+ case QueryType::QUERY_UPDATE:
559
+ return " UPDATE" ;
560
+ case QueryType::QUERY_ALTER:
561
+ return " ALTER" ;
562
+ case QueryType::QUERY_DELETE:
563
+ return " DELETE" ;
564
+ case QueryType::QUERY_COPY:
565
+ return " COPY" ;
566
+ case QueryType::QUERY_ANALYZE:
567
+ return " ANALYZE" ;
568
+ case QueryType::QUERY_RENAME:
569
+ return " RENAME" ;
570
+ case QueryType::QUERY_PREPARE:
571
+ return " PREPARE" ;
572
+ case QueryType::QUERY_EXECUTE:
573
+ return " EXECUTE" ;
574
+ case QueryType::QUERY_SELECT:
575
+ return " SELECT" ;
576
+ case QueryType::QUERY_OTHER:
577
+ default :
578
+ return " OTHER" ;
556
579
}
557
580
}
558
581
559
582
QueryType StringToQueryType (const std::string &str) {
560
- static std::unordered_map<std::string, QueryType> querytype_string_map {
561
- {" BEGIN" , QueryType::QUERY_BEGIN}, {" COMMIT" , QueryType::QUERY_COMMIT},
562
- {" ROLLBACK" , QueryType::QUERY_ROLLBACK}, {" CREATE DATABASE" , QueryType::QUERY_CREATE_DB},
563
- {" CREATE INDEX" , QueryType::QUERY_CREATE_INDEX}, {" CREATE TABLE" , QueryType::QUERY_CREATE_TABLE},
564
- {" DROP" , QueryType::QUERY_DROP}, {" INSERT" , QueryType::QUERY_INSERT},
565
- {" SET" , QueryType::QUERY_SET}, {" SHOW" , QueryType::QUERY_SHOW},
566
- {" SHOW" , QueryType::QUERY_SHOW}, {" UPDATE" , QueryType::QUERY_UPDATE},
567
- {" ALTER" , QueryType::QUERY_ALTER}, {" DELETE" , QueryType::QUERY_DELETE},
568
- {" COPY" , QueryType::QUERY_COPY}, {" ANALYZE" , QueryType::QUERY_ANALYZE},
569
- {" RENAME" , QueryType::QUERY_RENAME}, {" PREPARE" , QueryType::QUERY_PREPARE},
570
- {" EXECUTE" , QueryType::QUERY_EXECUTE}, {" SELECT" , QueryType::QUERY_SELECT},
571
- {" CREATE TRIGGER" , QueryType::QUERY_CREATE_TRIGGER}, {" CREATE SCHEMA" , QueryType::QUERY_CREATE_SCHEMA},
572
- {" CREATE VIEW" , QueryType::QUERY_CREATE_VIEW}, {" OTHER" , QueryType::QUERY_OTHER},
583
+ static std::unordered_map<std::string, QueryType> querytype_string_map{
584
+ {" BEGIN" , QueryType::QUERY_BEGIN},
585
+ {" COMMIT" , QueryType::QUERY_COMMIT},
586
+ {" ROLLBACK" , QueryType::QUERY_ROLLBACK},
587
+ {" CREATE DATABASE" , QueryType::QUERY_CREATE_DB},
588
+ {" CREATE INDEX" , QueryType::QUERY_CREATE_INDEX},
589
+ {" CREATE TABLE" , QueryType::QUERY_CREATE_TABLE},
590
+ {" DROP" , QueryType::QUERY_DROP},
591
+ {" INSERT" , QueryType::QUERY_INSERT},
592
+ {" SET" , QueryType::QUERY_SET},
593
+ {" SHOW" , QueryType::QUERY_SHOW},
594
+ {" SHOW" , QueryType::QUERY_SHOW},
595
+ {" UPDATE" , QueryType::QUERY_UPDATE},
596
+ {" ALTER" , QueryType::QUERY_ALTER},
597
+ {" DELETE" , QueryType::QUERY_DELETE},
598
+ {" COPY" , QueryType::QUERY_COPY},
599
+ {" ANALYZE" , QueryType::QUERY_ANALYZE},
600
+ {" RENAME" , QueryType::QUERY_RENAME},
601
+ {" PREPARE" , QueryType::QUERY_PREPARE},
602
+ {" EXECUTE" , QueryType::QUERY_EXECUTE},
603
+ {" SELECT" , QueryType::QUERY_SELECT},
604
+ {" CREATE TRIGGER" , QueryType::QUERY_CREATE_TRIGGER},
605
+ {" CREATE SCHEMA" , QueryType::QUERY_CREATE_SCHEMA},
606
+ {" CREATE VIEW" , QueryType::QUERY_CREATE_VIEW},
607
+ {" OTHER" , QueryType::QUERY_OTHER},
573
608
};
574
- std::unordered_map<std::string, QueryType>::iterator it = querytype_string_map.find (str);
609
+ std::unordered_map<std::string, QueryType>::iterator it =
610
+ querytype_string_map.find (str);
575
611
if (it != querytype_string_map.end ()) {
576
- return it -> second;
612
+ return it-> second ;
577
613
} else {
578
614
return QueryType::QUERY_INVALID;
579
615
}
580
616
}
581
617
582
- QueryType StatementTypeToQueryType (StatementType stmt_type, const parser::SQLStatement* sql_stmt) {
618
+ QueryType StatementTypeToQueryType (StatementType stmt_type,
619
+ const parser::SQLStatement *sql_stmt) {
583
620
LOG_TRACE (" %s" , StatementTypeToString (stmt_type).c_str ());
584
- static std::unordered_map<StatementType, QueryType, EnumHash<StatementType>> type_map {
585
- {StatementType::EXECUTE, QueryType::QUERY_EXECUTE},
586
- {StatementType::PREPARE, QueryType::QUERY_PREPARE},
587
- {StatementType::INSERT, QueryType::QUERY_INSERT},
588
- {StatementType::UPDATE, QueryType::QUERY_UPDATE},
589
- {StatementType::DELETE, QueryType::QUERY_DELETE},
590
- {StatementType::COPY, QueryType::QUERY_COPY},
591
- {StatementType::ANALYZE, QueryType::QUERY_ANALYZE},
592
- {StatementType::ALTER, QueryType::QUERY_ALTER},
593
- {StatementType::DROP, QueryType::QUERY_DROP},
594
- {StatementType::SELECT, QueryType::QUERY_SELECT},
595
- {StatementType::VARIABLE_SET, QueryType::QUERY_SET},
596
- };
621
+ static std::unordered_map<StatementType, QueryType, EnumHash<StatementType>>
622
+ type_map{
623
+ {StatementType::EXECUTE, QueryType::QUERY_EXECUTE},
624
+ {StatementType::PREPARE, QueryType::QUERY_PREPARE},
625
+ {StatementType::INSERT, QueryType::QUERY_INSERT},
626
+ {StatementType::UPDATE, QueryType::QUERY_UPDATE},
627
+ {StatementType::DELETE, QueryType::QUERY_DELETE},
628
+ {StatementType::COPY, QueryType::QUERY_COPY},
629
+ {StatementType::ANALYZE, QueryType::QUERY_ANALYZE},
630
+ {StatementType::ALTER, QueryType::QUERY_ALTER},
631
+ {StatementType::DROP, QueryType::QUERY_DROP},
632
+ {StatementType::SELECT, QueryType::QUERY_SELECT},
633
+ {StatementType::VARIABLE_SET, QueryType::QUERY_SET},
634
+ };
597
635
QueryType query_type = QueryType::QUERY_OTHER;
598
- std::unordered_map<StatementType, QueryType, EnumHash<StatementType>>::iterator it = type_map.find (stmt_type);
636
+ std::unordered_map<StatementType, QueryType,
637
+ EnumHash<StatementType>>::iterator it =
638
+ type_map.find (stmt_type);
599
639
if (it != type_map.end ()) {
600
- query_type = it -> second;
640
+ query_type = it-> second ;
601
641
} else {
602
- switch (stmt_type) {
642
+ switch (stmt_type) {
603
643
case StatementType::TRANSACTION: {
604
- switch (static_cast <const parser::TransactionStatement*>(sql_stmt) ->type ) {
605
- case parser::TransactionStatement::CommandType::kBegin :query_type = QueryType::QUERY_BEGIN;
644
+ switch (
645
+ static_cast <const parser::TransactionStatement *>(sql_stmt)->type ) {
646
+ case parser::TransactionStatement::CommandType::kBegin :
647
+ query_type = QueryType::QUERY_BEGIN;
606
648
break ;
607
- case parser::TransactionStatement::CommandType::kCommit :query_type = QueryType::QUERY_COMMIT;
649
+ case parser::TransactionStatement::CommandType::kCommit :
650
+ query_type = QueryType::QUERY_COMMIT;
608
651
break ;
609
- case parser::TransactionStatement::CommandType::kRollback :query_type = QueryType::QUERY_ROLLBACK;
652
+ case parser::TransactionStatement::CommandType::kRollback :
653
+ query_type = QueryType::QUERY_ROLLBACK;
610
654
break ;
611
655
}
612
656
break ;
613
657
}
614
658
case StatementType::CREATE: {
615
- switch (static_cast <const parser::CreateStatement*>(sql_stmt) ->type ) {
616
- case parser::CreateStatement::CreateType::kDatabase :query_type = QueryType::QUERY_CREATE_DB;
659
+ switch (static_cast <const parser::CreateStatement *>(sql_stmt)->type ) {
660
+ case parser::CreateStatement::CreateType::kDatabase :
661
+ query_type = QueryType::QUERY_CREATE_DB;
617
662
break ;
618
- case parser::CreateStatement::CreateType::kIndex :query_type = QueryType::QUERY_CREATE_INDEX;
663
+ case parser::CreateStatement::CreateType::kIndex :
664
+ query_type = QueryType::QUERY_CREATE_INDEX;
619
665
break ;
620
- case parser::CreateStatement::CreateType::kTable :query_type = QueryType::QUERY_CREATE_TABLE;
666
+ case parser::CreateStatement::CreateType::kTable :
667
+ query_type = QueryType::QUERY_CREATE_TABLE;
621
668
break ;
622
- case parser::CreateStatement::CreateType::kTrigger :query_type = QueryType::QUERY_CREATE_TRIGGER;
669
+ case parser::CreateStatement::CreateType::kTrigger :
670
+ query_type = QueryType::QUERY_CREATE_TRIGGER;
623
671
break ;
624
- case parser::CreateStatement::CreateType::kSchema :query_type = QueryType::QUERY_CREATE_SCHEMA;
672
+ case parser::CreateStatement::CreateType::kSchema :
673
+ query_type = QueryType::QUERY_CREATE_SCHEMA;
625
674
break ;
626
- case parser::CreateStatement::CreateType::kView :query_type = QueryType::QUERY_CREATE_VIEW;
675
+ case parser::CreateStatement::CreateType::kView :
676
+ query_type = QueryType::QUERY_CREATE_VIEW;
627
677
break ;
628
678
}
629
679
break ;
@@ -708,9 +758,9 @@ std::string PostgresValueTypeToString(PostgresValueType type) {
708
758
return " DECIMAL" ;
709
759
}
710
760
default : {
711
- throw ConversionException (
712
- StringUtil::Format ( " No string conversion for PostgresValueType value '%d'" ,
713
- static_cast <int >(type)));
761
+ throw ConversionException (StringUtil::Format (
762
+ " No string conversion for PostgresValueType value '%d'" ,
763
+ static_cast <int >(type)));
714
764
}
715
765
}
716
766
return " INVALID" ;
@@ -766,7 +816,7 @@ PostgresValueType StringToPostgresValueType(const std::string &str) {
766
816
return PostgresValueType::DECIMAL;
767
817
} else {
768
818
throw ConversionException (StringUtil::Format (
769
- " No PostgresValueType conversion from string '%s'" , upper_str.c_str ()));
819
+ " No PostgresValueType conversion from string '%s'" , upper_str.c_str ()));
770
820
}
771
821
return PostgresValueType::INVALID;
772
822
}
@@ -1087,13 +1137,15 @@ std::string IndexTypeToString(IndexType type) {
1087
1137
case IndexType::SKIPLIST: {
1088
1138
return " SKIPLIST" ;
1089
1139
}
1140
+ case IndexType::ART: {
1141
+ return " ART" ;
1142
+ }
1090
1143
default : {
1091
1144
throw ConversionException (
1092
1145
StringUtil::Format (" No string conversion for IndexType value '%d'" ,
1093
1146
static_cast <int >(type)));
1094
1147
}
1095
1148
}
1096
- return " INVALID" ;
1097
1149
}
1098
1150
1099
1151
IndexType StringToIndexType (const std::string &str) {
@@ -1108,6 +1160,8 @@ IndexType StringToIndexType(const std::string &str) {
1108
1160
return IndexType::HASH;
1109
1161
} else if (upper_str == " SKIPLIST" ) {
1110
1162
return IndexType::SKIPLIST;
1163
+ } else if (upper_str == " ART" ) {
1164
+ return IndexType::ART;
1111
1165
} else {
1112
1166
throw ConversionException (StringUtil::Format (
1113
1167
" No IndexType conversion from string '%s'" , upper_str.c_str ()));
0 commit comments