001package gudusoft.gsqlparser.nodes.flink; 002 003import gudusoft.gsqlparser.TSourceToken; 004import gudusoft.gsqlparser.nodes.TParseTreeNode; 005import gudusoft.gsqlparser.nodes.TParseTreeVisitor; 006 007/** 008 * Represents a key-value property in Flink's WITH clause. 009 * 010 * <p>Syntax:</p> 011 * <pre> 012 * 'property_name' = 'property_value' 013 * </pre> 014 * 015 * <p>Example:</p> 016 * <pre> 017 * 'connector' = 'kafka' 018 * 'topic' = 'my-topic' 019 * </pre> 020 */ 021public class TFlinkTableProperty extends TParseTreeNode { 022 private TSourceToken propertyKey; 023 private TSourceToken propertyValue; 024 025 /** 026 * Initialize with key only. 027 * @param arg1 the property key token 028 */ 029 public void init(Object arg1) { 030 propertyKey = (TSourceToken) arg1; 031 } 032 033 /** 034 * Initialize with key and value. 035 * @param arg1 the property key token 036 * @param arg2 the property value token 037 */ 038 public void init(Object arg1, Object arg2) { 039 init(arg1); 040 propertyValue = (TSourceToken) arg2; 041 } 042 043 /** 044 * Get the property key (e.g., 'connector'). 045 * @return the property key token 046 */ 047 public TSourceToken getPropertyKey() { 048 return propertyKey; 049 } 050 051 /** 052 * Get the property value (e.g., 'kafka'). 053 * @return the property value token 054 */ 055 public TSourceToken getPropertyValue() { 056 return propertyValue; 057 } 058 059 /** 060 * Get the property key as a string without quotes. 061 * @return the property key string 062 */ 063 public String getKeyString() { 064 if (propertyKey == null) return null; 065 String key = propertyKey.toString(); 066 // Remove surrounding quotes if present 067 if (key.length() >= 2 && 068 ((key.startsWith("'") && key.endsWith("'")) || 069 (key.startsWith("\"") && key.endsWith("\"")))) { 070 return key.substring(1, key.length() - 1); 071 } 072 return key; 073 } 074 075 /** 076 * Get the property value as a string without quotes. 077 * @return the property value string 078 */ 079 public String getValueString() { 080 if (propertyValue == null) return null; 081 String value = propertyValue.toString(); 082 // Remove surrounding quotes if present 083 if (value.length() >= 2 && 084 ((value.startsWith("'") && value.endsWith("'")) || 085 (value.startsWith("\"") && value.endsWith("\"")))) { 086 return value.substring(1, value.length() - 1); 087 } 088 return value; 089 } 090 091 @Override 092 public void accept(TParseTreeVisitor v) { 093 v.preVisit(this); 094 v.postVisit(this); 095 } 096 097 @Override 098 public void acceptChildren(TParseTreeVisitor v) { 099 v.preVisit(this); 100 v.postVisit(this); 101 } 102}