Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partially supported directives #655

Open
wants to merge 8 commits into
base: relational-directives
Choose a base branch
from

Conversation

shrverma
Copy link

@shrverma shrverma commented Jul 27, 2023

Implements relational transform for the following directives:

  • Change-column-case-names
  • Quantization
  • Cleanse-column-names
  • Set-headers
  • Set-type
  • Diff-date
  • Format-date
  • Set-charset
  • Fail
  • Record-condition-filter
  • Column-expression
  • Decode
  • Encode
  • Write-as-CSV
  • Write-as-JSON-Map

@@ -105,4 +109,19 @@ public static String getColumnTypeExp(String toType, String column, @Nullable In
return column;
}
}

public static List<String> generateListCols(RelationalTranformContext relationalTranformContext) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can rename to generateColumnList or generateColumnNameList

Comment on lines 116 to 122
IntStream.range(0, Math.min(columnNames.size(), columns.size()))
.forEach(i -> columnExpMap.put(columns.get(i), expressionFactory.get().compile(columnNames.get(i))));

if (columnNames.size() > columns.size()) {
IntStream.range(columns.size(), columnNames.size())
.forEach(i -> columnExpMap.put(columnNames.get(i), expressionFactory.get().compile(columnNames.get(i))));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can move to a function with a simple for loop

return relation.select(colmap);
}

public static Map<String, Expression> generateCleanseColumnMap(Collection columns,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make private

if (!expressionFactory.isPresent()) {
return new InvalidRelation("Cannot find an Expression Factory");
}
List<String> columnNames = SqlExpressionGenerator.generateListCols(relationalTranformContext);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this method gets the list of input columns from the transform context, which is not really related to "generating a SQL expression". I would either suggest keeping this in a different util class or you can just rename the method to getColumnList

}

return relation.setColumn("tempColumn", expressionFactory.get().compile(
String.format("if(%s, raise_error(\"Condition '%s' evaluated to true. " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can move this to a variable

if (!expressionFactory.isPresent()) {
return new InvalidRelation("Cannot find an Expression Factory");
}
if (method.toString().equalsIgnoreCase("base64")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as decode changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants