001package gudusoft.gsqlparser.nodes; 002/* 003 * Date: 2010-12-22 004 * Time: 14:33:43 005 */ 006 007import gudusoft.gsqlparser.ESqlClause; 008import gudusoft.gsqlparser.TCustomSqlStatement; 009 010import java.util.ArrayList; 011 012/** 013 * represents values() clause. {@link #getRows()} returns the rows in this value clause. 014 */ 015public class TValueClause extends TParseTreeNode { 016 017 /** 018 * The name a vendor gives the {@code position}-th column (1-based) of a VALUES table that has no column list, or 019 * null when the vendor names none (Mantis 4823): PostgreSQL, Greenplum, Redshift and Snowflake call them column1, 020 * column2, ...; Spark SQL and Databricks col1, col2, .... The single rule for the names TSQLResolver2 resolves and 021 * the columns dlineage creates. 022 */ 023 public static String defaultColumnName(gudusoft.gsqlparser.EDbVendor vendor, int position) { 024 if (vendor == null || position < 1) { 025 return null; 026 } 027 switch (vendor) { 028 case dbvpostgresql: 029 case dbvgreenplum: 030 case dbvredshift: 031 case dbvsnowflake: 032 return "column" + position; 033 case dbvsparksql: 034 case dbvdatabricks: 035 return "col" + position; 036 default: 037 return null; 038 } 039 } 040 private TValueRowItemList valueRows = null; 041 private TObjectNameList nameList = null; 042 043 public TObjectNameList getNameList() { 044 return nameList; 045 } 046 047 /** 048 * @deprecated As of v2.3.6.9, please use {@link #getRows()} instead 049 * The first row of the value clause. 050 * 051 * @return The first row of the value clause. 052 */ 053 public TValueRowItemList getValueRows() { 054 return valueRows;//rows.get(0); 055 } 056 057 058 059 /** 060 * Rows in the values clause. 061 * @return Rows in the values clause. 062 */ 063 public ArrayList<TResultColumnList> getRows() { 064 return rows; 065 } 066 067 private ArrayList <TResultColumnList> rows = new ArrayList<>(); 068 069 public void append(TResultColumnList list){ 070 rows.add(list); 071 } 072 073 public void init(Object arg1) 074 { 075 if (arg1 instanceof TValueRowItemList){ 076 valueRows = (TValueRowItemList)arg1; 077 078 }else if (arg1 instanceof TResultColumnList){ 079 append((TResultColumnList)arg1); 080 } 081 082 } 083 084 public void init(Object arg1,Object arg2) 085 { 086 init(arg1); 087 if (arg2 != null){ 088 nameList = (TObjectNameList)arg2; 089 } 090 } 091 092 public void doParse(TCustomSqlStatement psql, ESqlClause plocation){ 093 //for(int i=0;i<rows.size();i++){ 094 for(TResultColumnList item:rows){ 095 item.doParse(psql,plocation); 096 } 097 //} 098 } 099 100 public void accept(TParseTreeVisitor v){ 101 v.preVisit(this); 102 v.postVisit(this); 103 } 104 105 public void acceptChildren(TParseTreeVisitor v){ 106 v.preVisit(this); 107 for(int i=0;i<rows.size();i++){ 108 rows.get(i).acceptChildren(v); 109 } 110 v.postVisit(this); 111 } 112 113 public void setValueRows(TValueRowItemList valueRows) { 114 this.valueRows = valueRows; 115 } 116 117 public void setNameList(TObjectNameList nameList) { 118 this.nameList = nameList; 119 } 120}