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

Supports filling elements through templates for expression #1144

Closed
wants to merge 2 commits into from

Conversation

xiaocai2333
Copy link
Contributor

No description provided.

@sre-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: xiaocai2333
To complete the pull request process, please assign yhmo after the PR has been reviewed.
You can assign the PR to them by writing /assign @yhmo in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Comment on lines +242 to +255
DataType lastType = DataType.UNRECOGNIZED;
boolean sameType = true;
for (Object obj : array) {
TemplateValue tv = deduceTemplateValue(obj);
builder.addArray(tv);
if (lastType == DataType.UNRECOGNIZED) {
lastType = tv.getType();
} else if (lastType != tv.getType()) {
sameType = false;
}
DataType arrayType = sameType ? lastType : DataType.JSON;
builder.setElementType(arrayType);
builder.setSameType(sameType);
}

Choose a reason for hiding this comment

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

Suggested change
DataType lastType = DataType.UNRECOGNIZED;
boolean sameType = true;
for (Object obj : array) {
TemplateValue tv = deduceTemplateValue(obj);
builder.addArray(tv);
if (lastType == DataType.UNRECOGNIZED) {
lastType = tv.getType();
} else if (lastType != tv.getType()) {
sameType = false;
}
DataType arrayType = sameType ? lastType : DataType.JSON;
builder.setElementType(arrayType);
builder.setSameType(sameType);
}
DataType lastType = DataType.UNRECOGNIZED;
boolean sameType = true;
for (Object obj : array) {
TemplateValue tv = deduceTemplateValue(obj);
builder.addArray(tv);
if (sameType && lastType != DataType.UNRECOGNIZED && lastType != tv.getType()) {
sameType = false;
}
lastType = tv.getType();
}
DataType arrayType = sameType ? lastType : DataType.JSON;
builder.setElementType(arrayType);
builder.setSameType(sameType);

return builder.build();
}

public static TemplateValue deduceTemplateValue(Object value) {

Choose a reason for hiding this comment

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

nit: I prefer long method names that convey the exact action, maybe deduceAndCreateTemplateValue

DataType elementType = DataType.None;
int i = 0;

for (Object element : (List<?>) value) {

Choose a reason for hiding this comment

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

ditto

@xiaocai2333
Copy link
Contributor Author

/close
track with #1145

@sre-ci-robot
Copy link

@xiaocai2333: Closed this PR.

In response to this:

/close
track with #1145

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

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

Successfully merging this pull request may close these issues.

4 participants