@Test public void testToSQL() { ColumnParseNode columnParseNode = new ColumnParseNode(TableName.create("SCHEMA1", "TABLE1"), "V"); CastParseNode castParseNode = new CastParseNode(columnParseNode, PLong.INSTANCE, null, null, false); StringBuilder stringBuilder = new StringBuilder(); castParseNode.toSQL(null, stringBuilder); assertEquals(" CAST(TABLE1.V AS BIGINT)", stringBuilder.toString()); }
@Override public void toSQL(ColumnResolver resolver, StringBuilder buf) { List<ParseNode> children = getChildren(); buf.append(" CAST("); children.get(0).toSQL(resolver, buf); buf.append(" AS "); boolean isArray = dt.isArrayType(); PDataType type = isArray ? PDataType.arrayBaseType(dt) : dt; buf.append(type.getSqlTypeName()); if (maxLength != null) { buf.append('('); buf.append(maxLength); if (scale != null) { buf.append(','); buf.append(scale); } buf.append(')'); } if (isArray) { buf.append(' '); buf.append(PDataType.ARRAY_TYPE_SUFFIX); } buf.append(")"); }
CastParseNode extends UnaryParseNode { @Override public void toSQL(ColumnResolver resolver, StringBuilder buf) { List<ParseNode> children = getChildren(); buf.append(" CAST("); children.get(0).toSQL(resolver, buf); buf.append(" AS "); boolean isArray = dt.isArrayType(); PDataType type = isArray ? PDataType.arrayBaseType(dt) : dt; buf.append(type.getSqlTypeName()); if (maxLength != null) { buf.append('('); buf.append(maxLength); if (scale != null) { buf.append(','); buf.append(scale); } buf.append(')'); } if (isArray) { buf.append(' '); buf.append(PDataType.ARRAY_TYPE_SUFFIX); } buf.append(")"); } }
CastParseNode extends UnaryParseNode { @Override public void toSQL(ColumnResolver resolver, StringBuilder buf) { List<ParseNode> children = getChildren(); buf.append(" CAST("); children.get(0).toSQL(resolver, buf); buf.append(" AS "); boolean isArray = dt.isArrayType(); PDataType type = isArray ? PDataType.arrayBaseType(dt) : dt; buf.append(type.getSqlTypeName()); if (maxLength != null) { buf.append('('); buf.append(maxLength); if (scale != null) { buf.append(','); buf.append(scale); } buf.append(')'); } if (isArray) { buf.append(' '); buf.append(PDataType.ARRAY_TYPE_SUFFIX); } buf.append(")"); } CastParseNode(ParseNode expr, String dataType, Integer maxLength, Integer scale, boolean arr);   CastParseNode(ParseNode expr, PDataType dataType, Integer maxLength, Integer scale, boolean arr); }
CastParseNode extends UnaryParseNode { @Override public void toSQL(ColumnResolver resolver, StringBuilder buf) { List<ParseNode> children = getChildren(); buf.append(" CAST("); children.get(0).toSQL(resolver, buf); buf.append(" AS "); boolean isArray = dt.isArrayType(); PDataType type = isArray ? PDataType.arrayBaseType(dt) : dt; buf.append(type.getSqlTypeName()); if (maxLength != null) { buf.append('('); buf.append(maxLength); if (scale != null) { buf.append(','); buf.append(scale); } buf.append(')'); } if (isArray) { buf.append(' '); buf.append(PDataType.ARRAY_TYPE_SUFFIX); } buf.append(")"); } CastParseNode(ParseNode expr, String dataType, Integer maxLength, Integer scale, boolean arr);   CastParseNode(ParseNode expr, PDataType dataType, Integer maxLength, Integer scale, boolean arr); @Override T accept(ParseNodeVisitor<T> visitor); PDataType getDataType(); Integer getMaxLength(); Integer getScale(); @Override int hashCode(); @Override boolean equals(Object obj); @Override void toSQL(ColumnResolver resolver, StringBuilder buf); }
CastParseNode extends UnaryParseNode { @Override public void toSQL(ColumnResolver resolver, StringBuilder buf) { List<ParseNode> children = getChildren(); buf.append(" CAST("); children.get(0).toSQL(resolver, buf); buf.append(" AS "); boolean isArray = dt.isArrayType(); PDataType type = isArray ? PDataType.arrayBaseType(dt) : dt; buf.append(type.getSqlTypeName()); if (maxLength != null) { buf.append('('); buf.append(maxLength); if (scale != null) { buf.append(','); buf.append(scale); } buf.append(')'); } if (isArray) { buf.append(' '); buf.append(PDataType.ARRAY_TYPE_SUFFIX); } buf.append(")"); } CastParseNode(ParseNode expr, String dataType, Integer maxLength, Integer scale, boolean arr);   CastParseNode(ParseNode expr, PDataType dataType, Integer maxLength, Integer scale, boolean arr); @Override T accept(ParseNodeVisitor<T> visitor); PDataType getDataType(); Integer getMaxLength(); Integer getScale(); @Override int hashCode(); @Override boolean equals(Object obj); @Override void toSQL(ColumnResolver resolver, StringBuilder buf);  }