@@ -791,7 +791,14 @@ std::shared_ptr<TableCatalogObject> Catalog::GetTableObject(
791
791
// ===--------------------------------------------------------------------===//
792
792
// ALTER TABLE
793
793
// ===--------------------------------------------------------------------===//
794
- /* Helper function for alter table, called internally
794
+
795
+ /* *
796
+ * @brief Helper function for alter table, called internally
797
+ * @param database_oid database to which the table belongs to
798
+ * @param table_oid table to which the column belongs to
799
+ * @param new_schema the new table schema
800
+ * @param txn the transaction Context
801
+ * @return TransactionContext ResultType(SUCCESS or FAILURE)
795
802
*/
796
803
ResultType Catalog::AlterTable (
797
804
UNUSED_ATTRIBUTE oid_t database_oid, UNUSED_ATTRIBUTE oid_t table_oid,
@@ -803,37 +810,65 @@ ResultType Catalog::AlterTable(
803
810
return ResultType::SUCCESS;
804
811
}
805
812
813
+ /* *
814
+ * @brief Add new columns to the table.
815
+ * @param database_name database to which the table belongs to
816
+ * @param table_name table to which the column belongs to
817
+ * @param columns the column to be added
818
+ * @param txn the transaction Context
819
+ * @return TransactionContext ResultType(SUCCESS or FAILURE)
820
+ *
821
+ */
806
822
ResultType Catalog::AddColumn (
807
823
UNUSED_ATTRIBUTE const std::string &database_name,
808
824
UNUSED_ATTRIBUTE const std::string &table_name,
809
825
UNUSED_ATTRIBUTE const std::vector<std::string> &columns,
810
826
UNUSED_ATTRIBUTE concurrency::TransactionContext *txn) {
827
+ // TODO: perform ADD Operation
811
828
return ResultType::SUCCESS;
812
829
}
813
830
831
+ /* *
832
+ * @brief Drop the column from the table.
833
+ * @param database_name database to which the table belongs to
834
+ * @param table_name table to which the columns belong to
835
+ * @param columns the columns to be dropped
836
+ * @param txn the transaction Context
837
+ * @return TransactionContext ResultType(SUCCESS or FAILURE)
838
+ */
839
+
814
840
ResultType Catalog::DropColumn (
815
841
UNUSED_ATTRIBUTE const std::string &database_name,
816
842
UNUSED_ATTRIBUTE const std::string &table_name,
817
843
UNUSED_ATTRIBUTE const std::vector<std::string> &columns,
818
844
UNUSED_ATTRIBUTE concurrency::TransactionContext *txn) {
845
+ // TODO: perform DROP Operation
819
846
return ResultType::SUCCESS;
820
847
}
821
848
822
- ResultType Catalog::ChangeColumnName (const std::string &database_name,
823
- const std::string &table_name,
824
- const std::vector<std::string> &old_names,
825
- const std::vector<std::string> &names,
826
- concurrency::TransactionContext *txn) {
849
+ /* *
850
+ * @brief Change the column name in the catalog.
851
+ * @param database_name database to which the table belongs to
852
+ * @param table_name table to which the column belongs to
853
+ * @param columns the column to be dropped
854
+ * @param txn the transaction Context
855
+ * @return TransactionContext ResultType(SUCCESS or FAILURE)
856
+ */
857
+ ResultType Catalog::RenameColumn (const std::string &database_name,
858
+ const std::string &table_name,
859
+ const std::string &old_name,
860
+ const std::string &new_name,
861
+ concurrency::TransactionContext *txn) {
827
862
if (txn == nullptr ) {
828
863
throw CatalogException (" Change Column requires transaction." );
829
864
}
830
865
831
- if (old_names. size () == 0 || names .size () == 0 ) {
832
- throw CatalogException (" No names are given ." );
866
+ if (new_name .size () == 0 ) {
867
+ throw CatalogException (" Name can not be empty string ." );
833
868
}
834
869
835
- LOG_TRACE (" Change Column Name %s to %s" , old_names[ 0 ] .c_str (),
836
- names[ 0 ] .c_str ());
870
+ LOG_TRACE (" Change Column Name %s to %s" , old_name .c_str (),
871
+ new_name .c_str ());
837
872
838
873
try {
839
874
// Get table from the name
@@ -844,23 +879,23 @@ ResultType Catalog::ChangeColumnName(const std::string &database_name,
844
879
// Currently we only support change the first column name!
845
880
846
881
// Check the validity of old name and the new name
847
- oid_t columnId = schema->GetColumnID (names[ 0 ] );
882
+ oid_t columnId = schema->GetColumnID (new_name );
848
883
if (columnId != INVALID_OID) {
849
884
throw CatalogException (" New column already exists in the table." );
850
885
}
851
- columnId = schema->GetColumnID (old_names[ 0 ] );
886
+ columnId = schema->GetColumnID (old_name );
852
887
if (columnId == INVALID_OID) {
853
888
throw CatalogException (" Old column does not exist in the table." );
854
889
}
855
890
856
891
// Change column name in the global schema
857
- schema->ChangeColumnName (columnId, names[ 0 ] );
892
+ schema->ChangeColumnName (columnId, new_name );
858
893
859
894
// Change cached ColumnCatalog
860
895
oid_t table_oid = Catalog::GetInstance ()
861
896
->GetTableObject (database_name, table_name, txn)
862
897
->GetTableOid ();
863
- catalog::ColumnCatalog::GetInstance ()->DeleteColumn (table_oid, old_names[ 0 ] ,
898
+ catalog::ColumnCatalog::GetInstance ()->DeleteColumn (table_oid, old_name ,
864
899
txn);
865
900
auto new_column = schema->GetColumn (columnId);
866
901
catalog::ColumnCatalog::GetInstance ()->InsertColumn (
0 commit comments