Skip to content

Commit

Permalink
put a default type hint for PythonCallableSource
Browse files Browse the repository at this point in the history
  • Loading branch information
ihji committed May 12, 2022
1 parent 514e325 commit 2fce769
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ private PythonExternalTransform(String fullyQualifiedName, String expansionServi
this.expansionService = expansionService;
this.kwargsMap = new TreeMap<>();
this.typeHints = new HashMap<>();
// TODO(BEAM-14458): remove a default type hint for PythonCallableSource when BEAM-14458 is
// resolved
this.typeHints.put(
PythonCallableSource.class, Schema.FieldType.logicalType(new PythonCallable()));
argsArray = new Object[] {};
}

Expand Down Expand Up @@ -204,14 +208,12 @@ Row buildOrGetKwargsRow() {
// Types that are not one of following are considered custom types.
// * Java primitives
// * Type String
// * Type PythonCallableSource
// * Any Type explicitly annotated by withTypeHint()
// * Type Row
private boolean isCustomType(java.lang.Class<?> type) {
boolean val =
!(ClassUtils.isPrimitiveOrWrapper(type)
|| type == String.class
|| type == PythonCallableSource.class
|| typeHints.containsKey(type)
|| Row.class.isAssignableFrom(type));
return val;
Expand Down Expand Up @@ -268,8 +270,6 @@ private Schema generateSchemaDirectly(
if (field instanceof Row) {
// Rows are used as is but other types are converted to proper field types.
builder.addRowField(fieldName, ((Row) field).getSchema());
} else if (field instanceof PythonCallableSource) {
builder.addField(fieldName, Schema.FieldType.logicalType(new PythonCallable()));
} else if (typeHints.containsKey(field.getClass())) {
builder.addField(fieldName, typeHints.get(field.getClass()));
} else {
Expand Down

0 comments on commit 2fce769

Please sign in to comment.