001package gudusoft.gsqlparser.stmt; 002 003import gudusoft.gsqlparser.*; 004import gudusoft.gsqlparser.nodes.*; 005import gudusoft.gsqlparser.nodes.flink.TFlinkWatermarkClause; 006import gudusoft.gsqlparser.nodes.flink.TFlinkWithClause; 007import gudusoft.gsqlparser.nodes.hive.*; 008import gudusoft.gsqlparser.nodes.netezza.TExternalTableOption; 009import gudusoft.gsqlparser.nodes.oracle.TPhysicalProperties; 010import gudusoft.gsqlparser.nodes.postgresql.TInheritsClause; 011import gudusoft.gsqlparser.nodes.postgresql.TPartitionBoundSpecSqlNode; 012import gudusoft.gsqlparser.nodes.teradata.TIndexDefinition; 013import gudusoft.gsqlparser.nodes.teradata.TTeradataPeriodForClause; 014 015import java.util.*; 016 017/** 018 * SQL create table statement. 019 * <br> 020 * {@link #getTargetTable} returns the created table. {@link #getColumnList()} returns columns created in the table. 021 * <br> {@link #getTableConstraints()} returns table level constraints if any. 022 * <br> {@link #getSubQuery()} returns select statement that generate data for this table. 023 * <br><br>Example: 024 * <pre> 025 * CREATE TABLE dbo.Employee (EmployeeID int PRIMARY KEY CLUSTERED); 026 * </pre> 027 * Table:dbo.Employee can be fetched from {@link #getTargetTable} or the first element of {@link #tables} 028 * <br> column definitions: can be fetched from {@link #getColumnList} 029 * <br> 030 * table constraints: {@link #getTableConstraints} 031 * 032 */ 033public class TCreateTableSqlStatement extends TCustomSqlStatement { 034 035 036 public TInheritsClause getInheritsClause() { 037 return inheritsClause; 038 } 039 040 private TInheritsClause inheritsClause; 041 042 private TBaseTablePartition tablePartition; 043 044 045 public TBaseTablePartition getTablePartition() { 046 return tablePartition; 047 } 048 049 public void setPartitionBoundSpec(TPartitionBoundSpecSqlNode partitionBoundSpec) { 050 this.partitionBoundSpec = partitionBoundSpec; 051 } 052 053 public TPartitionBoundSpecSqlNode getPartitionBoundSpec() { 054 return partitionBoundSpec; 055 } 056 057 /** 058 * postgresql PartitionBoundSpec 059 * https://www.postgresql.org/docs/current/sql-createtable.html 060 */ 061 private TPartitionBoundSpecSqlNode partitionBoundSpec; 062 063 public TTableProperties getTableProperties() { 064 return tableProperties; 065 } 066 067 public void setTableProperties(TTableProperties tableProperties) { 068 this.tableProperties = tableProperties; 069 } 070 071 private TTableProperties tableProperties; 072 073 public enum TableSourceType {normal,subquery,like,clone,copy,partitionOf,forExchangeWith}; 074 private TableSourceType tableSourceType = TableSourceType.normal; 075 076 private List<String> externalTableOptionList = null; 077 078 /** 079 * sql server create external table with options 080 * @return 081 */ 082 public List<String> getExternalTableOptionNames(){ 083 return TBaseType.getOptionNames(externalTableOptionList); 084 } 085 086 /** 087 * sql server create external table with option. 088 * 089 * @param optionName 090 * @return 091 */ 092 public String getExternalTableOption(String optionName){ 093 return TBaseType.getOption(externalTableOptionList,optionName); 094 } 095 096 public TableSourceType getTableSourceType() { 097 return tableSourceType; 098 } 099 100 private TObjectName cloneSourceTable = null; 101 102 public TObjectName getCloneSourceTable() { 103 return cloneSourceTable; 104 } 105 106 private TExternalTableOption externalTableOption = null; 107 108 public TExternalTableOption getExternalTableOption() { 109 return externalTableOption; 110 } 111 112 private TExpression partitionByExpr; 113 114 public void setPartitionByExpr(TExpression partitionByExpr) { 115 this.partitionByExpr = partitionByExpr; 116 } 117 118 /** 119 * Bigquery partition by expr 120 * 121 * @return expr 122 */ 123 public TExpression getPartitionByExpr() { 124 return partitionByExpr; 125 } 126 127 private String awsSnsTopic = null; 128 129 public void setAwsSnsTopic(String awsSnsTopic) { 130 this.awsSnsTopic = awsSnsTopic; 131 } 132 133 public String getAwsSnsTopic() { 134 return awsSnsTopic; 135 } 136 137 private TObjectNameList partitionColumnList; 138 139 public void setPartitionColumnList(TObjectNameList partitionColumnList) { 140 this.partitionColumnList = partitionColumnList; 141 } 142 143 public TObjectNameList getPartitionColumnList() { 144 return partitionColumnList; 145 } 146 147 public void setFileFormatName(String fileFormatName) { 148 this.fileFormatName = fileFormatName; 149 } 150 151 public void setFileFormatType(String fileFormatType) { 152 this.fileFormatType = fileFormatType; 153 } 154 155 public String getFileFormatName() { 156 return fileFormatName; 157 } 158 159 public String getFileFormatType() { 160 return fileFormatType; 161 } 162 163 private String fileFormatName = null; 164 private String fileFormatType = null; 165 166 private String regex_pattern; 167 168 public void setRegex_pattern(String regex_pattern) { 169 this.regex_pattern = regex_pattern; 170 } 171 172 public String getRegex_pattern() { 173 return regex_pattern; 174 } 175 176 private TStageLocation stageLocation; 177 178 public void setStageLocation(TStageLocation stageLocation) { 179 this.stageLocation = stageLocation; 180 } 181 182 public TStageLocation getStageLocation() { 183 return stageLocation; 184 } 185 186 public void setTableOptions(ArrayList<TCreateTableOption> tableOptions) { 187 this.tableOptions = tableOptions; 188 } 189 190 public ArrayList<TCreateTableOption> getTableOptions() { 191 return tableOptions; 192 } 193 194 private ArrayList<TCreateTableOption> tableOptions; 195 196 public void setOnFilegroup(TDummy onFilegroup) { 197 this.onFilegroup = onFilegroup; 198 } 199 200 public TDummy getOnFilegroup() { 201 return onFilegroup; 202 } 203 204 private TDummy onFilegroup = null; 205 206 /** 207 * Oracle physical properties 208 * @return Oracle physical properties 209 */ 210 public TPhysicalProperties getPhysicalProperties() { 211 return physicalProperties; 212 } 213 214 private TPhysicalProperties physicalProperties; 215 216 private EnumSet<ETableKind> tableKinds = EnumSet.noneOf(ETableKind.class); 217 218 public void setTableKinds(EnumSet<ETableKind> tableKinds) { 219 this.tableKinds = tableKinds; 220 } 221 222 /** 223 * Type of this table 224 * @return Type of this table 225 */ 226 public EnumSet<ETableKind> getTableKinds() { 227 return tableKinds; 228 } 229 230 private TTable asTable; 231 232 /** 233 * Netezza, Teradata, as table name. 234 * @return as table name 235 */ 236 public TTable getAsTable() { 237 return asTable; 238 } 239 240 private boolean externalTable; 241 242 /** 243 * @deprecated As of v1.9.7.2 , replace by {@link #isExternal} 244 * <br> 245 * Netezza, whether it is a external table 246 * @return true if it's netezza create external table 247 */ 248 public boolean isExternalTable() { 249 return externalTable; 250 } 251 252 private ArrayList <TIndexDefinition> indexDefinitions; 253 254 /** 255 * Teradata index definition 256 * 257 * <pre>UNIQUE PRIMARY INDEX (storeid, productid, salesdate)</pre> 258 * @return list of index definition 259 */ 260 public ArrayList<TIndexDefinition> getIndexDefinitions() { 261 return indexDefinitions; 262 } 263 264 /** 265 * Teradata PERIOD FOR clauses that define derived temporal columns. 266 * A table can have multiple PERIOD FOR clauses (e.g., one for VALIDTIME and one for TRANSACTIONTIME). 267 */ 268 private ArrayList<TTeradataPeriodForClause> periodForClauses; 269 270 /** 271 * Returns the list of Teradata PERIOD FOR clauses in this CREATE TABLE statement. 272 * PERIOD FOR clauses define derived columns that represent time periods from two date/timestamp columns. 273 * 274 * @return list of PERIOD FOR clauses, may be null or empty if none are defined 275 */ 276 public ArrayList<TTeradataPeriodForClause> getPeriodForClauses() { 277 return periodForClauses; 278 } 279 280 /** 281 * Flink WATERMARK clauses that define event-time processing. 282 * A table typically has at most one WATERMARK clause. 283 */ 284 private ArrayList<TFlinkWatermarkClause> watermarkClauses; 285 286 /** 287 * Returns the list of Flink WATERMARK clauses in this CREATE TABLE statement. 288 * WATERMARK clauses define how watermarks are generated for event-time processing. 289 * 290 * @return list of WATERMARK clauses, may be null or empty if none are defined 291 */ 292 public ArrayList<TFlinkWatermarkClause> getWatermarkClauses() { 293 return watermarkClauses; 294 } 295 296 /** 297 * Returns the first Flink WATERMARK clause in this CREATE TABLE statement. 298 * Typically only one WATERMARK clause is defined per table. 299 * 300 * @return the first WATERMARK clause, or null if none are defined 301 */ 302 public TFlinkWatermarkClause getWatermarkClause() { 303 return (watermarkClauses != null && !watermarkClauses.isEmpty()) 304 ? watermarkClauses.get(0) 305 : null; 306 } 307 308 private boolean external; 309 private boolean ifNotExists; 310 private TObjectName tableLocation; 311 private TObjectName tableComment; 312 private THiveTableProperties hiveTableProperties; 313 private THiveTablePartition hiveTablePartition; 314 private THiveTableBuckets hiveTableBuckets; 315 private THiveTableSkewed hiveTableSkewed; 316 private THiveRowFormat hiveRowFormat; 317 private THiveTableFileFormat hiveTableFileFormat; 318 private TObjectName likeTableName; 319 320 /** 321 * Flink WITH clause containing connector properties. 322 */ 323 private TFlinkWithClause flinkWithClause; 324 325 /** 326 * Get the Flink WITH clause containing connector properties. 327 * 328 * <p>Flink SQL uses the WITH clause to specify connector properties:</p> 329 * <pre> 330 * CREATE TABLE my_table ( 331 * id BIGINT, 332 * name STRING 333 * ) WITH ( 334 * 'connector' = 'kafka', 335 * 'topic' = 'my-topic', 336 * 'properties.bootstrap.servers' = 'localhost:9092', 337 * 'format' = 'json' 338 * ); 339 * </pre> 340 * 341 * @return the Flink WITH clause, or null if not present 342 */ 343 public TFlinkWithClause getFlinkWithClause() { 344 return flinkWithClause; 345 } 346 347 /** 348 * Set the Flink WITH clause. 349 * @param flinkWithClause the Flink WITH clause 350 */ 351 public void setFlinkWithClause(TFlinkWithClause flinkWithClause) { 352 this.flinkWithClause = flinkWithClause; 353 } 354 355 /** 356 * Hive, Impala,Netezza,snowflake whether it is an external table 357 * @return whether it is an external table 358 */ 359 public boolean isExternal() { 360 return external; 361 } 362 363 /** 364 * Hive, impala table row format 365 * @return table row format 366 */ 367 public THiveRowFormat getHiveRowFormat() { 368 return hiveRowFormat; 369 } 370 371 /** 372 * Hive, Impala table buckets 373 * @return table buckets 374 */ 375 public THiveTableBuckets getHiveTableBuckets() { 376 return hiveTableBuckets; 377 } 378 379 /** 380 * Hive, Impala table file format 381 * @return table file format 382 */ 383 public THiveTableFileFormat getHiveTableFileFormat() { 384 return hiveTableFileFormat; 385 } 386 387 /** 388 * Hive, Impala table partition 389 * @return table partition 390 */ 391 public THiveTablePartition getHiveTablePartition() { 392 return hiveTablePartition; 393 } 394 395 /** 396 * Hive, Impala table properties 397 * @return table properties 398 */ 399 public THiveTableProperties getHiveTableProperties() { 400 return hiveTableProperties; 401 } 402 403 /** 404 * Hive, Impala skewed by clause. 405 * @return skewed by clause. 406 */ 407 public THiveTableSkewed getHiveTableSkewed() { 408 return hiveTableSkewed; 409 } 410 411 /** 412 * Hive, Impala, if not exists clause 413 * @return true if not exists clause is used in create table statement 414 */ 415 public boolean isIfNotExists() { 416 return ifNotExists; 417 } 418 419 /** 420 * Greenplum, table used in like clause. 421 * <br>Hive, Impala, table used in like clause. 422 * @return table used in like clause. 423 */ 424 public TObjectName getLikeTableName() { 425 return likeTableName; 426 } 427 428 /** 429 * Hive, Impala, comment of the table. 430 * @return comment of the table. 431 */ 432 public TObjectName getTableComment() { 433 return tableComment; 434 } 435 436 /** 437 * Hive, Impala, location of the table. 438 * @return location of the table. 439 */ 440 public TObjectName getTableLocation() { 441 return tableLocation; 442 } 443 444 private TObjectName rowTypeName; 445 private TObjectName superTableName; 446 447 /** 448 * Informix, typename used in of type clause. 449 * 450 * @return row type name 451 */ 452 public TObjectName getRowTypeName() { 453 return rowTypeName; 454 } 455 456 /** 457 * Informix, table name used in the under clause. 458 * @return table name used in the under clause. 459 */ 460 public TObjectName getSuperTableName() { 461 return superTableName; 462 } 463 464 /** 465 * Data of the created table is derived from this select statement. 466 * 467 * @return {@link gudusoft.gsqlparser.stmt.TSelectSqlStatement} used in create table. 468 */ 469 public TSelectSqlStatement getSubQuery() { 470 return subQuery; 471 } 472 473 private TSelectSqlStatement subQuery = null; 474 private TExecuteSqlStatement executePreparedStatement = null;//greenplum 475 476 public TExecuteSqlStatement getExecutePreparedStatement() { 477 return executePreparedStatement; 478 } 479 480 481 482 private TPTNodeList <TMySQLCreateTableOption> mySQLTableOptionList; 483 484 /** 485 * MySQL, option used in create table such as engine, auto_increment and etc. 486 * @return option used in create table such as engine, auto_increment and etc. 487 */ 488 public TPTNodeList<TMySQLCreateTableOption> getMySQLTableOptionList() { 489 return mySQLTableOptionList; 490 } 491 492 public TCreateTableSqlStatement(EDbVendor dbvendor) { 493 super(dbvendor); 494 sqlstatementtype = ESqlStatementType.sstcreatetable; 495 } 496 497 void buildsql() { 498 } 499 500 void clear() { 501 } 502 503 String getasprettytext() { 504 return ""; 505 } 506 507 void iterate(TVisitorAbs pvisitor) { 508 } 509 510 private TObjectName tableName = null; 511 512 /** 513 * The first table in {@link #tables}, this is the same table as {@link #getTargetTable} 514 * 515 * @return The first table in {@link #tables} 516 */ 517 public TObjectName getTableName() { 518 return tables.getTable(0).getTableName(); 519 } 520 521 private boolean webTable = false; 522 523 public boolean isWebTable() { 524 return webTable; 525 } 526 527 528 private boolean readable; 529 530 public boolean isReadable() { 531 return readable; 532 } 533 534 public boolean isWritable() { 535 return writable; 536 } 537 538 private boolean writable; 539 540 private TConstant executeCmd; 541 542 543 public TConstant getExecuteCmd() { 544 return executeCmd; 545 } 546 547 548 private ArrayList<TConstant> locationFiles; 549 550 public void setLocationFiles(ArrayList<TConstant> locationFiles) { 551 this.locationFiles = locationFiles; 552 } 553 554 public ArrayList<TConstant> getLocationFiles() { 555 return locationFiles; 556 } 557 558 public int doParseStatement(TCustomSqlStatement psql) { 559 if (rootNode == null) return -1; 560 TCreateTableSqlNode createTableNode = (TCreateTableSqlNode)rootNode; 561 super.doParseStatement(psql); 562 this.tableKinds = createTableNode.getTableKinds(); 563 this.tableSourceType = createTableNode.getTableSourceType(); 564 this.setTargetTable(createTableNode.getTable()); 565 566 567 // move to TMetadataCollector 568 569// TSQLTable sqlTable = null; 570// if (getSqlEnv() != null) { 571// if (createTableNode.getTable() != null){ 572// sqlTable = getSqlEnv().addTable(createTableNode.getTable().getFullName(),true); 573// } 574// 575// if (getSqlEnv().getDefaultCatalogName() != null){ 576// if (createTableNode.getTable().getTableName().getDatabaseToken() == null){ 577// createTableNode.getTable().getTableName().setDatabaseToken(new TSourceToken(getSqlEnv().getDefaultCatalogName()),true); 578// } 579// } 580// 581// createTableNode.getTable().getTableName().setSqlEnv(getSqlEnv()); 582// } 583 584 // end of move to TMetadataCollector 585 586 externalTable = createTableNode.isExternalTable(); 587 physicalProperties = createTableNode.getPhysicalProperties(); 588 tableProperties = createTableNode.getTableProperties(); 589 this.tablePartition = createTableNode.getTablePartition(); 590 591 if (createTableNode.getNetezzaExternalTableOption() != null){ 592 this.externalTableOption = new TExternalTableOption(createTableNode.getNetezzaExternalTableOption().toString()); 593 } 594 595 mySQLTableOptionList = createTableNode.getMySQLTableOptionList(); 596 tableOptions = createTableNode.getTableOptions(); 597 if (tableOptions != null){ 598 for(int i=0;i<tableOptions.size();i++){ 599 tableOptions.get(i).doParse(this,ESqlClause.unknown); 600 } 601 } 602 603 superTableName = createTableNode.getSuperTableName(); 604 rowTypeName = createTableNode.getRowTypeName(); 605 onFilegroup = createTableNode.getOnFilegroup(); 606 cloneSourceTable = createTableNode.getCloneSourceTable(); 607 likeTableName = createTableNode.getLikeTableName(); 608 if (likeTableName != null){ 609 likeTableName.setDbObjectType(this.dbvendor,EDbObjectType.table); 610 } 611 partitionBoundSpec = createTableNode.getPartitionBoundSpec(); 612 613 tables.addTable(createTableNode.getTable()); 614 asTable = createTableNode.getAsTable(); 615 if (asTable != null) tables.addTable(asTable); 616 if ((createTableNode.getTableElementList() != null)&&(createTableNode.getTableElementList().size() >0 )){ 617 TTableElement te; 618 TColumnDefinition cd; 619 Set<String> columnNames = new LinkedHashSet<String>(); 620 for(int i=0; i<createTableNode.getTableElementList().size();i++){ 621 te = createTableNode.getTableElementList().getTableElement(i); 622 if (te.getType() == TTableElement.type_column_def) { 623 cd = te.getColumnDefinition(); 624 this.getColumnList().addColumn(cd); 625 626 cd.doParse(this, ESqlClause.createTable); 627 this.getTargetTable().getObjectNameReferences().addObjectName(cd.getColumnName()); 628 cd.getColumnName().setLocation(ESqlClause.createTable); 629 cd.getColumnName().setLinkedColumnDef(cd); 630 getTargetTable().getLinkedColumns().addObjectName(cd.getColumnName()); 631 cd.getColumnName().setSourceTable(getTargetTable()); 632 // move to TMetadataCollector 633// if (sqlTable != null){ 634// sqlTable.addColumn(cd.getColumnName().toString(),cd.getDatatype()); 635// //getTargetTable().setSqlTable(sqlTable); 636// } 637 if (!columnNames.add(cd.getColumnName().toString())){ 638 // find duplicate colum name 639 TSourceToken st = cd.getColumnName().getStartToken(); 640 this.parseerrormessagehandle(new TSyntaxError(st.getAstext(), st.lineNo, st.columnNo 641 ,"duplicate column name", EErrorType.spfatalerror 642 , TBaseType.MSG_ERROR_DUPLICATED_COLUMN_NAME,this,st.posinlist)); 643 644 } 645 } 646 else if (te.getType() == TTableElement.type_table_like){ 647 likeTableName = te.getParentTable(); 648 }else if (te.getType() == TTableElement.type_supplemental_logging){ 649 650 }else if (te.getType() == TTableElement.type_period_for_clause){ 651 // Teradata PERIOD FOR clause - derived temporal column 652 if (periodForClauses == null) { 653 periodForClauses = new ArrayList<TTeradataPeriodForClause>(); 654 } 655 periodForClauses.add(te.getPeriodForClause()); 656 }else if (te.getType() == TTableElement.type_flink_watermark){ 657 // Flink WATERMARK clause for event-time processing 658 if (watermarkClauses == null) { 659 watermarkClauses = new ArrayList<TFlinkWatermarkClause>(); 660 } 661 watermarkClauses.add(te.getFlinkWatermarkClause()); 662 }else{ 663 te.getConstraint().doParse(this,ESqlClause.unknown); 664 this.getTableConstraints().addConstraint(te.getConstraint()); 665 } 666 } 667 } 668 669 // column name list used when create table using a subquery. 670 TColumnDefinition t = null; 671 if ((createTableNode.getColumnList() != null)&&(createTableNode.getColumnList().size() > 0)){ 672 for(int i=0;i<createTableNode.getColumnList().size();i++){ 673 t = new TColumnDefinition(createTableNode.getColumnList().getObjectName(i)); 674 t.setStartToken(t.getColumnName().getStartToken()); 675 t.setEndToken(t.getColumnName().getEndToken()); 676 this.getColumnList().addColumn(t); 677 this.getTargetTable().getObjectNameReferences().addObjectName(createTableNode.getColumnList().getObjectName(i)); 678 getTargetTable().getLinkedColumns().addObjectName(createTableNode.getColumnList().getObjectName(i)); 679 createTableNode.getColumnList().getObjectName(i).setSourceTable(getTargetTable()); 680 // move to TMetadataCollector 681// if (sqlTable != null){ 682// sqlTable.addColumn(createTableNode.getColumnList().getObjectName(i).toString()); 683// } 684 } 685 } 686 687 if((subQuery == null) && (createTableNode.getSubQueryNode() != null) && (createTableNode.getSubQueryNode().getRelationExpr() == null)){ 688 subQuery = new TSelectSqlStatement(this.dbvendor); 689 subQuery.rootNode = createTableNode.getSubQueryNode(); 690 subQuery.doParseStatement(this); 691 692 693 // link column alias in subquery to table in create statement if columnList is not specified 694 if (createTableNode.getColumnList() == null){ 695 TSelectSqlStatement viewQuery = subQuery; 696 if (subQuery.isCombinedQuery()){ 697 viewQuery = subQuery.getRightStmt(); 698 } 699 700 if (viewQuery.getResultColumnList() != null) { 701 for(int i=0;i<viewQuery.getResultColumnList().size();i++){ 702 TResultColumn resultColumn = viewQuery.getResultColumnList().getResultColumn(i); 703 TObjectName aliasName = null; 704 if (resultColumn.getAliasClause() != null){ 705 if (resultColumn.getAliasClause().getColumns() != null){ 706 // select explode(str_to_map(regexp_replace(regexp_replace(regexp_replace(lower(t.input), '', ''), '',''), '', ''), '', '')) as (`key`, `value`) from B t1 707 for (int j=0;j<resultColumn.getAliasClause().getColumns().size();j++){ 708 TObjectName aliasName1 = resultColumn.getAliasClause().getColumns().getObjectName(j); 709 aliasName1.setLocation(ESqlClause.columnAlias); 710 resultColumn.getAliasNameList().add(aliasName1); 711 } 712 }else { 713 aliasName = TObjectName.createObjectName (this.dbvendor, EDbObjectType.column,resultColumn.getAliasClause().getAliasName().getStartToken()); 714 aliasName.getReferencedObjects().addObjectName(resultColumn.getAliasClause().getAliasName()); 715 aliasName.setLocation(resultColumn.getAliasClause().getAliasName().getLocation()); 716 } 717 }else{ 718 if (resultColumn.getExpr().getObjectOperand() != null){ 719 aliasName = TObjectName.createObjectName (this.dbvendor, EDbObjectType.column,resultColumn.getExpr().getObjectOperand().getPartToken()); 720 aliasName.getReferencedObjects().addObjectName(resultColumn.getExpr().getObjectOperand()); 721 aliasName.setLocation(resultColumn.getExpr().getObjectOperand().getLocation()); 722 } 723 } 724 725 if (aliasName != null){ 726 if (aliasName.getLocation() == ESqlClause.unknown){ 727 aliasName.setLocation(ESqlClause.columnAlias); 728 } 729 getTargetTable().getLinkedColumns().addObjectName(aliasName); 730 aliasName.setSourceTable(getTargetTable()); 731 resultColumn.setAliasName(aliasName.toString()); 732 733 // move to TMetadataCollector 734// if (sqlTable != null){ 735// sqlTable.addColumn(TSQLEnv.getObjectName(aliasName.toString())); 736// } 737 } 738 } 739 } 740 } 741 }else if ((createTableNode.getSubQueryNode() != null) && (createTableNode.getSubQueryNode().getRelationExpr() != null)){ 742 // CREATE TABLE a AS TABLE b 743 asTable = new TTable(createTableNode.getSubQueryNode().getRelationExpr().getRelationName()); 744 tables.addTable(asTable); 745 } 746 747 if (createTableNode.getExecuteSqlNode() != null){ 748 executePreparedStatement = new TExecuteSqlStatement(this.dbvendor); 749 executePreparedStatement.rootNode = createTableNode.getExecuteSqlNode(); 750 executePreparedStatement.doParseStatement(this); 751 } 752 753 external = createTableNode.isExternal(); 754 if (!external && tableKinds.contains(ETableKind.etkExternal)){ 755 external = true; 756 } 757 if (external){ 758 if (createTableNode.getOptionStartParenthesis() != null){ 759 externalTableOptionList = TBaseType.getArrayListBetweenTokens(createTableNode.getOptionStartParenthesis(),createTableNode.getOptionEndParenthesis(),false); 760 } 761 } 762 ifNotExists = createTableNode.isIfNotExists(); 763 if (createTableNode.getTableComment() != null){ 764 tableComment = createTableNode.getTableComment(); 765 } 766 767 locationFiles = createTableNode.getLocationFiles(); 768 readable = createTableNode.isReadable(); 769 writable = createTableNode.isWritable(); 770 executeCmd = createTableNode.getExecuteCmd(); 771 webTable = createTableNode.isWebTable(); 772 773 tableLocation = createTableNode.getTableLocation(); 774 hiveTableProperties = createTableNode.getHiveTableProperties(); 775 hiveTablePartition = createTableNode.getHiveTablePartition(); 776 hiveTableBuckets = createTableNode.getHiveTableBuckets(); 777 hiveRowFormat = createTableNode.getHiveRowFormat(); 778 hiveTableSkewed = createTableNode.getHiveTableSkewed(); 779 hiveTableFileFormat = createTableNode.getHiveTableFileFormat(); 780 flinkWithClause = createTableNode.getFlinkWithClause(); 781 if (likeTableName == null){ 782 likeTableName = createTableNode.getLikeTableName(); 783 } 784 indexDefinitions = createTableNode.getIndexDefinitions(); 785 if (indexDefinitions != null){ 786 for(int i=0;i<indexDefinitions.size();i++){ 787 indexDefinitions.get(i).doParse(this,ESqlClause.tableIndexOption); 788 } 789 } 790 791 inheritsClause = createTableNode.getInheritsClause(); 792 if (inheritsClause != null) { 793 for(int i=0;i<inheritsClause.getParentTables().size();i++){ 794 inheritsClause.getParentTables().getObjectName(i).setDbObjectType(this.dbvendor, EDbObjectType.table); 795 } 796 } 797 return 0; 798 } 799 800 /** 801 * table level constraints. 802 * @return List of table constraints of this table. 803 */ 804 public TConstraintList getTableConstraints() { 805 if (this.tableConstraints == null){ 806 this.tableConstraints = new TConstraintList(); 807 808 } 809 810 return tableConstraints; 811 } 812 813 /** 814 * columns created in create table statement. 815 * 816 * @return List of column definitions of this table. 817 */ 818 public TColumnDefinitionList getColumnList() { 819 if (this.columnList == null){ 820 this.columnList = new TColumnDefinitionList(); 821 822 } 823 return columnList; 824 } 825 826 private TColumnDefinitionList columnList = null; 827 private TConstraintList tableConstraints = null; 828 829 public void accept(TParseTreeVisitor v){ 830 v.preVisit(this); 831 v.postVisit(this); 832 } 833 834 public void acceptChildren(TParseTreeVisitor v){ 835 v.preVisit(this); 836 //tables.acceptChildren(v); 837 if (getTargetTable() != null) { 838 getTargetTable().acceptChildren(v); 839 } 840 this.getColumnList().acceptChildren(v); 841 if ((this.getTableConstraints() != null)&&(this.getTableConstraints().size()>0)){ 842 this.getTableConstraints().acceptChildren(v); 843 } 844 if (this.getSubQuery() != null){ 845 this.getSubQuery().acceptChildren(v); 846 } 847 if (getHiveTablePartition() != null){ 848 getHiveTablePartition().acceptChildren(v); 849 } 850 v.postVisit(this); 851 } 852 853 public void setColumnList(TColumnDefinitionList columnList) { 854 this.columnList = columnList; 855 } 856 857 public void setAsTable(TTable asTable) { 858 this.asTable = asTable; 859 } 860 861 public void setExternalTable(boolean externalTable) { 862 this.externalTable = externalTable; 863 } 864 865 public void setIndexDefinitions(ArrayList<TIndexDefinition> indexDefinitions) { 866 this.indexDefinitions = indexDefinitions; 867 } 868 869 public void setExternal(boolean external) { 870 this.external = external; 871 } 872 873 public void setIfNotExists(boolean ifNotExists) { 874 this.ifNotExists = ifNotExists; 875 } 876 877 public void setTableLocation(TObjectName tableLocation) { 878 this.tableLocation = tableLocation; 879 } 880 881 public void setTableComment(TObjectName tableComment) { 882 this.tableComment = tableComment; 883 } 884 885 public void setHiveTableProperties(THiveTableProperties hiveTableProperties) { 886 this.hiveTableProperties = hiveTableProperties; 887 } 888 889 public void setHiveTablePartition(THiveTablePartition hiveTablePartition) { 890 this.hiveTablePartition = hiveTablePartition; 891 } 892 893 public void setHiveTableBuckets(THiveTableBuckets hiveTableBuckets) { 894 this.hiveTableBuckets = hiveTableBuckets; 895 } 896 897 public void setHiveTableSkewed(THiveTableSkewed hiveTableSkewed) { 898 this.hiveTableSkewed = hiveTableSkewed; 899 } 900 901 public void setHiveRowFormat(THiveRowFormat hiveRowFormat) { 902 this.hiveRowFormat = hiveRowFormat; 903 } 904 905 public void setHiveTableFileFormat(THiveTableFileFormat hiveTableFileFormat) { 906 this.hiveTableFileFormat = hiveTableFileFormat; 907 } 908 909 public void setLikeTableName(TObjectName likeTableName) { 910 this.likeTableName = likeTableName; 911 } 912 913 public void setRowTypeName(TObjectName rowTypeName) { 914 this.rowTypeName = rowTypeName; 915 } 916 917 public void setSuperTableName(TObjectName superTableName) { 918 this.superTableName = superTableName; 919 } 920 921 public void setSubQuery(TSelectSqlStatement subQuery) { 922 this.subQuery = subQuery; 923 } 924 925 public void setExecutePreparedStatement(TExecuteSqlStatement executePreparedStatement) { 926 this.executePreparedStatement = executePreparedStatement; 927 } 928 929 public void setMySQLTableOptionList(TPTNodeList<TMySQLCreateTableOption> mySQLTableOptionList) { 930 this.mySQLTableOptionList = mySQLTableOptionList; 931 } 932 933 public void setTableName(TObjectName tableName) { 934 this.tableName = tableName; 935 } 936 937 public void setTableConstraints(TConstraintList tableConstraints) { 938 this.tableConstraints = tableConstraints; 939 } 940}