1616
1717package com .google .cloud .spanner .jdbc ;
1818
19+ import com .google .cloud .spanner .Dialect ;
1920import com .google .cloud .spanner .ResultSet ;
2021import com .google .cloud .spanner .Struct ;
2122import com .google .cloud .spanner .Type ;
@@ -154,6 +155,7 @@ public Type getSpannerType() {
154155 },
155156 FLOAT64 {
156157 private final Set <Class <?>> classes = new HashSet <>(Arrays .asList (Float .class , Double .class ));
158+ private final Set <String > aliases = new HashSet <>(Collections .singletonList ("float8" ));
157159
158160 @ Override
159161 public int getSqlType () {
@@ -184,6 +186,11 @@ public List<Double> getArrayElements(ResultSet rs, int columnIndex) {
184186 public Type getSpannerType () {
185187 return Type .float64 ();
186188 }
189+
190+ @ Override
191+ public Set <String > getPostgreSQLAliases () {
192+ return aliases ;
193+ }
187194 },
188195 INT64 {
189196 private final Set <Class <?>> classes =
@@ -220,6 +227,9 @@ public Type getSpannerType() {
220227 }
221228 },
222229 NUMERIC {
230+
231+ private final Set <String > aliases = new HashSet <>(Collections .singletonList ("decimal" ));
232+
223233 @ Override
224234 public int getSqlType () {
225235 return Types .NUMERIC ;
@@ -244,6 +254,11 @@ public List<BigDecimal> getArrayElements(ResultSet rs, int columnIndex) {
244254 public Type getSpannerType () {
245255 return Type .numeric ();
246256 }
257+
258+ @ Override
259+ public Set <String > getPostgreSQLAliases () {
260+ return aliases ;
261+ }
247262 },
248263 PG_NUMERIC {
249264 @ Override
@@ -272,6 +287,8 @@ public Type getSpannerType() {
272287 }
273288 },
274289 STRING {
290+ private final Set <String > aliases = new HashSet <>(Arrays .asList ("varchar" , "text" ));
291+
275292 @ Override
276293 public int getSqlType () {
277294 return Types .NVARCHAR ;
@@ -296,6 +313,11 @@ public List<String> getArrayElements(ResultSet rs, int columnIndex) {
296313 public Type getSpannerType () {
297314 return Type .string ();
298315 }
316+
317+ @ Override
318+ public Set <String > getPostgreSQLAliases () {
319+ return aliases ;
320+ }
299321 },
300322 JSON {
301323 @ Override
@@ -498,6 +520,21 @@ public Type getSpannerType() {
498520
499521 public abstract Type getSpannerType ();
500522
523+ public Set <String > getPostgreSQLAliases () {
524+ return Collections .emptySet ();
525+ }
526+
527+ /***
528+ * @param typeName type of the column
529+ * @return true if type name matches current type name or matches with one of postgres aliases
530+ * or if it matches equivalent postgres type.
531+ */
532+ boolean matches (String typeName ) {
533+ return getTypeName ().equalsIgnoreCase (typeName )
534+ || getPostgreSQLAliases ().contains (typeName .toLowerCase ())
535+ || getSpannerType ().getSpannerTypeName (Dialect .POSTGRESQL ).equalsIgnoreCase (typeName );
536+ }
537+
501538 // TODO: Implement and use this method for all types.
502539 public int getPrecision () {
503540 throw new UnsupportedOperationException ();
0 commit comments