@@ -19,7 +19,7 @@ class Bigquery extends Common
1919 public const NUMERIC_LENGTH_CONST = 29 ;
2020 public const BIGNUMERIC_LENGTH_CONST = 38 ;
2121
22- // public const TYPE_ARRAY = 'ARRAY'; // todo we decided not support array right now
22+ public const TYPE_ARRAY = 'ARRAY ' ;
2323
2424 public const TYPE_BOOL = 'BOOL ' ; // NULL,TRUE,FALSE
2525
@@ -59,9 +59,10 @@ class Bigquery extends Common
5959
6060 public const TYPE_STRING = 'STRING ' ; // STRING(L) L is a positive INT64 value
6161
62- // public const TYPE_STRUCT = 'STRUCT'; // todo we decided not support struct right now
62+ public const TYPE_STRUCT = 'STRUCT ' ;
6363
6464 public const TYPES = [
65+ self ::TYPE_ARRAY ,
6566 self ::TYPE_BOOL ,
6667 self ::TYPE_BYTES ,
6768 self ::TYPE_DATE ,
@@ -76,6 +77,7 @@ class Bigquery extends Common
7677 self ::TYPE_BIGNUMERIC ,
7778 self ::TYPE_FLOAT64 ,
7879 self ::TYPE_STRING ,
80+ self ::TYPE_STRUCT ,
7981
8082 // aliases
8183 self ::TYPE_INT ,
@@ -115,16 +117,29 @@ public function __construct(string $type, array $options = [])
115117 public function getTypeOnlySQLDefinition (): string
116118 {
117119 $ out = $ this ->getType ();
118- $ length = $ this ->getLength ();
119- if ($ length !== null && $ length !== '' ) {
120- $ out .= sprintf ('(%s) ' , $ length );
120+ if (strtoupper ($ out ) === self ::TYPE_ARRAY || strtoupper ($ out ) === self ::TYPE_STRUCT ) {
121+ $ length = $ this ->getLength ();
122+ if ($ length !== null && $ length !== '' ) {
123+ $ out .= sprintf ('<%s> ' , $ length );
124+ }
125+ } else {
126+ $ length = $ this ->getLength ();
127+ if ($ length !== null && $ length !== '' ) {
128+ $ out .= sprintf ('(%s) ' , $ length );
129+ }
121130 }
122131 return $ out ;
123132 }
124133
125134 public function getSQLDefinition (): string
126135 {
127136 $ definition = $ this ->getTypeOnlySQLDefinition ();
137+
138+ if (strtoupper ($ this ->getType ()) === self ::TYPE_ARRAY
139+ || strtoupper ($ this ->getType ()) === self ::TYPE_STRUCT
140+ ) {
141+ return $ definition ;
142+ }
128143 if ($ this ->getDefault () !== null ) {
129144 $ definition .= ' DEFAULT ' . $ this ->getDefault ();
130145 }
@@ -244,6 +259,9 @@ private function validateLength(string $type, $length = null): void
244259 case self ::TYPE_BIGDECIMAL :
245260 $ valid = $ this ->validateBigNumericLength ($ length , 76 , 38 );
246261 break ;
262+ case self ::TYPE_ARRAY :
263+ case self ::TYPE_STRUCT :
264+ break ; // We don't check for this types
247265 default :
248266 if ($ length !== null && $ length !== '' ) {
249267 $ valid = false ;
0 commit comments