@@ -552,6 +552,16 @@ func TestParseDDL(t *testing.T) {
552552 shard_id INT64 AS (MOD(FARM_FINGERPRINT(user_id), 19)) STORED,
553553 ) PRIMARY KEY(user_id);
554554
555+ -- Table has a column with a default value.
556+ CREATE TABLE DefaultCol (
557+ Name STRING(MAX) NOT NULL,
558+ Age INT64 DEFAULT (0),
559+ ) PRIMARY KEY (Name);
560+
561+ ALTER TABLE DefaultCol ALTER COLUMN Age DROP DEFAULT;
562+ ALTER TABLE DefaultCol ALTER COLUMN Age SET DEFAULT (0);
563+ ALTER TABLE DefaultCol ALTER COLUMN Age STRING(MAX) DEFAULT ("0");
564+
555565 -- Trailing comment at end of file.
556566 ` , & DDL {Filename : "filename" , List : []DDLStmt {
557567 & CreateTable {
@@ -795,6 +805,49 @@ func TestParseDDL(t *testing.T) {
795805 PrimaryKey : []KeyPart {{Column : "user_id" }},
796806 Position : line (66 ),
797807 },
808+
809+ & CreateTable {
810+ Name : "DefaultCol" ,
811+ Columns : []ColumnDef {
812+ {Name : "Name" , Type : Type {Base : String , Len : MaxLen }, NotNull : true , Position : line (77 )},
813+ {
814+ Name : "Age" , Type : Type {Base : Int64 },
815+ Default : IntegerLiteral (0 ),
816+ Position : line (78 ),
817+ },
818+ },
819+ PrimaryKey : []KeyPart {{Column : "Name" }},
820+ Position : line (76 ),
821+ },
822+ & AlterTable {
823+ Name : "DefaultCol" ,
824+ Alteration : AlterColumn {
825+ Name : "Age" ,
826+ Alteration : DropDefault {},
827+ },
828+ Position : line (81 ),
829+ },
830+ & AlterTable {
831+ Name : "DefaultCol" ,
832+ Alteration : AlterColumn {
833+ Name : "Age" ,
834+ Alteration : SetDefault {
835+ Default : IntegerLiteral (0 ),
836+ },
837+ },
838+ Position : line (82 ),
839+ },
840+ & AlterTable {
841+ Name : "DefaultCol" ,
842+ Alteration : AlterColumn {
843+ Name : "Age" ,
844+ Alteration : SetColumnType {
845+ Type : Type {Base : String , Len : MaxLen },
846+ Default : StringLiteral ("0" ),
847+ },
848+ },
849+ Position : line (83 ),
850+ },
798851 }, Comments : []* Comment {
799852 {Marker : "#" , Start : line (2 ), End : line (2 ),
800853 Text : []string {"This is a comment." }},
@@ -815,9 +868,10 @@ func TestParseDDL(t *testing.T) {
815868
816869 {Marker : "--" , Isolated : true , Start : line (43 ), End : line (43 ), Text : []string {"Table with generated column." }},
817870 {Marker : "--" , Isolated : true , Start : line (49 ), End : line (49 ), Text : []string {"Table with row deletion policy." }},
871+ {Marker : "--" , Isolated : true , Start : line (75 ), End : line (75 ), Text : []string {"Table has a column with a default value." }},
818872
819873 // Comment after everything else.
820- {Marker : "--" , Isolated : true , Start : line (75 ), End : line (75 ), Text : []string {"Trailing comment at end of file." }},
874+ {Marker : "--" , Isolated : true , Start : line (85 ), End : line (85 ), Text : []string {"Trailing comment at end of file." }},
821875 }}},
822876 // No trailing comma:
823877 {`ALTER TABLE T ADD COLUMN C2 INT64` , & DDL {Filename : "filename" , List : []DDLStmt {
0 commit comments