@@ -69,7 +69,8 @@ class ClickHousePlatform extends AbstractPlatform
69
69
public function getBooleanTypeDeclarationSQL (array $ columnDef ) : string
70
70
{
71
71
return $ this ->prepareDeclarationSQL (
72
- UnsignedNumericalClickHouseType::UNSIGNED_CHAR . NumericalClickHouseType::TYPE_INT . BitNumericalClickHouseType::EIGHT_BIT ,
72
+ UnsignedNumericalClickHouseType::UNSIGNED_CHAR .
73
+ NumericalClickHouseType::TYPE_INT . BitNumericalClickHouseType::EIGHT_BIT ,
73
74
$ columnDef
74
75
);
75
76
}
@@ -80,7 +81,8 @@ public function getBooleanTypeDeclarationSQL(array $columnDef) : string
80
81
public function getIntegerTypeDeclarationSQL (array $ columnDef ) : string
81
82
{
82
83
return $ this ->prepareDeclarationSQL (
83
- $ this ->_getCommonIntegerTypeDeclarationSQL ($ columnDef ) . NumericalClickHouseType::TYPE_INT . BitNumericalClickHouseType::THIRTY_TWO_BIT ,
84
+ $ this ->_getCommonIntegerTypeDeclarationSQL ($ columnDef ) .
85
+ NumericalClickHouseType::TYPE_INT . BitNumericalClickHouseType::THIRTY_TWO_BIT ,
84
86
$ columnDef
85
87
);
86
88
}
@@ -99,7 +101,8 @@ public function getBigIntTypeDeclarationSQL(array $columnDef) : string
99
101
public function getSmallIntTypeDeclarationSQL (array $ columnDef ) : string
100
102
{
101
103
return $ this ->prepareDeclarationSQL (
102
- $ this ->_getCommonIntegerTypeDeclarationSQL ($ columnDef ) . NumericalClickHouseType::TYPE_INT . BitNumericalClickHouseType::SIXTEEN_BIT ,
104
+ $ this ->_getCommonIntegerTypeDeclarationSQL ($ columnDef ) .
105
+ NumericalClickHouseType::TYPE_INT . BitNumericalClickHouseType::SIXTEEN_BIT ,
103
106
$ columnDef
104
107
);
105
108
}
@@ -199,6 +202,9 @@ protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) : string
199
202
: StringClickHouseType::TYPE_STRING ;
200
203
}
201
204
205
+ /**
206
+ * {@inheritDoc}
207
+ */
202
208
public function getVarcharTypeDeclarationSQL (array $ field )
203
209
{
204
210
if (! isset ($ field ['length ' ])) {
@@ -730,7 +736,8 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options
730
736
$ eventDateColumnName = $ options ['eventDateColumn ' ];
731
737
}
732
738
$ dateColumnParams ['name ' ] = $ eventDateColumnName ;
733
- $ columns = [$ eventDateColumnName => $ dateColumnParams ] + $ columns ; // insert into very beginning
739
+ // insert into very beginning
740
+ $ columns = [$ eventDateColumnName => $ dateColumnParams ] + $ columns ;
734
741
735
742
/**
736
743
* Primary key section
@@ -762,7 +769,8 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options
762
769
! $ columns [$ options ['versionColumn ' ]]['type ' ] instanceof DateTimeType
763
770
) {
764
771
throw new \Exception (
765
- 'For ReplacingMergeTree tables `versionColumn` must be any of UInt* family, or Date, or DateTime types. ' .
772
+ 'For ReplacingMergeTree tables `versionColumn` must be any of UInt* family,
773
+ or Date, or DateTime types. ' .
766
774
get_class ($ columns [$ options ['versionColumn ' ]]['type ' ]) . ' given. '
767
775
);
768
776
}
@@ -773,10 +781,13 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options
773
781
$ engineOptions .= ') ' ;
774
782
}
775
783
776
- $ columnListSql = $ this ->getColumnDeclarationListSQL ($ columns );
777
- $ query = 'CREATE TABLE ' . $ tableName . ' ( ' . $ columnListSql . ') ENGINE = ' . $ engine . $ engineOptions ;
778
-
779
- $ sql [] = $ query ;
784
+ $ sql [] = sprintf (
785
+ 'CREATE TABLE %s (%s) ENGINE = %s%s ' ,
786
+ $ tableName ,
787
+ $ this ->getColumnDeclarationListSQL ($ columns ),
788
+ $ engine ,
789
+ $ engineOptions
790
+ );
780
791
781
792
return $ sql ;
782
793
}
@@ -884,6 +895,9 @@ protected function _getAlterTableIndexForeignKeySQL(TableDiff $diff)
884
895
throw DBALException::notSupported (__METHOD__ );
885
896
}
886
897
898
+ /**
899
+ * @param mixed[] $columnDef
900
+ */
887
901
protected function prepareDeclarationSQL (string $ declarationSQL , array $ columnDef ) : string
888
902
{
889
903
if (array_key_exists ('notnull ' , $ columnDef ) && $ columnDef ['notnull ' ] === false ) {
@@ -1019,7 +1033,10 @@ public function getListDatabasesSQL() : string
1019
1033
*/
1020
1034
public function getListTableColumnsSQL ($ table , $ database = null ) : string
1021
1035
{
1022
- return 'DESCRIBE TABLE ' . ($ database ? $ this ->quoteSingleIdentifier ($ database ) . '. ' : '' ) . $ this ->quoteSingleIdentifier ($ table );
1036
+ return sprintf (
1037
+ 'DESCRIBE TABLE %s ' ,
1038
+ ($ database ? $ this ->quoteSingleIdentifier ($ database ) . '. ' : '' ) . $ this ->quoteSingleIdentifier ($ table )
1039
+ );
1023
1040
}
1024
1041
1025
1042
/**
@@ -1078,6 +1095,9 @@ public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration) : strin
1078
1095
return $ this ->prepareDeclarationSQL (DatableClickHouseType::TYPE_DATE_TIME , $ fieldDeclaration );
1079
1096
}
1080
1097
1098
+ /**
1099
+ * {@inheritDoc}
1100
+ */
1081
1101
public function getTimeTypeDeclarationSQL (array $ fieldDeclaration ) : string
1082
1102
{
1083
1103
return $ this ->prepareDeclarationSQL (StringClickHouseType::TYPE_STRING , $ fieldDeclaration );
@@ -1234,17 +1254,25 @@ public function getDefaultValueDeclarationSQL($field) : string
1234
1254
return '' ;
1235
1255
}
1236
1256
1237
- $ default = " DEFAULT ' " . $ field ['default ' ] . "' " ;
1238
- if ($ fieldType = (string ) ($ field ['type ' ] ?? null )) {
1257
+ $ default = " DEFAULT ' " . $ field ['default ' ] . "' " ;
1258
+ $ fieldType = $ field ['type ' ] ?? null ;
1259
+ if ($ fieldType !== null ) {
1239
1260
if (in_array ($ fieldType , [
1240
1261
'Integer ' ,
1241
1262
'SmallInt ' ,
1242
1263
'Float ' ,
1243
- ]) || ($ fieldType === 'BigInt ' && Type::getType ('BigInt ' )->getBindingType () === ParameterType::INTEGER )) {
1264
+ ]) ||
1265
+ (
1266
+ $ fieldType === 'BigInt '
1267
+ && Type::getType ('BigInt ' )->getBindingType () === ParameterType::INTEGER )
1268
+ ) {
1244
1269
$ default = ' DEFAULT ' . $ field ['default ' ];
1245
- } elseif ($ fieldType === DatableClickHouseType::TYPE_DATE_TIME && $ field ['default ' ] === $ this ->getCurrentTimestampSQL ()) {
1270
+ } elseif ($ fieldType === DatableClickHouseType::TYPE_DATE_TIME &&
1271
+ $ field ['default ' ] === $ this ->getCurrentTimestampSQL ()
1272
+ ) {
1246
1273
$ default = ' DEFAULT ' . $ this ->getCurrentTimestampSQL ();
1247
- } elseif ($ fieldType === DatableClickHouseType::TYPE_DATE ) { // TODO check if string matches constant date like 'dddd-yy-mm' and quote it
1274
+ } elseif (// TODO check if string matches constant date like 'dddd-yy-mm' and quote it
1275
+ $ fieldType === DatableClickHouseType::TYPE_DATE ) {
1248
1276
$ default = ' DEFAULT ' . $ field ['default ' ];
1249
1277
}
1250
1278
}
0 commit comments