Skip to content

[CALCITE-2780] Replace UnmodifiableArrayList with JDK Functions#997

Closed
belugabehr wants to merge 1 commit intoapache:masterfrom
belugabehr:CALCITE-2780
Closed

[CALCITE-2780] Replace UnmodifiableArrayList with JDK Functions#997
belugabehr wants to merge 1 commit intoapache:masterfrom
belugabehr:CALCITE-2780

Conversation

@belugabehr
Copy link
Contributor

Less is more.

public List<SqlNode> getOperandList() {
return UnmodifiableArrayList.of(operands); // not immutable, but quick
// not immutable, but quick
return Collections.unmodifiableList(Arrays.asList(operands));
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe worth adding the pattern to Util?
public static <T> List<T> Util.unmodifiableList(T[] elems)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wouldn't recommend it. You then expect others to have to know that such a utility exists and it will end up with some mixture of both.

Copy link
Contributor

@laurentgo laurentgo Jan 9, 2019

Choose a reason for hiding this comment

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

Util is used all over the place and provides lots of common functions regarding Collections.
If the concern is code consistency and preventing style mixture, maybe we should look at how to prevent "bad patterns" using checkstyle and similar checker tools...

Copy link
Contributor Author

@belugabehr belugabehr Jan 9, 2019

Choose a reason for hiding this comment

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

Thanks for the feedback. If that is what is required to get this change acceptable, then I will oblige. Just let me know.

If you want this change, what level of unit tests would you like?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see extra use of Collections.unmodifiableList() to wrap arrays in code base, and the pattern was already to use UnmodifiableArrayList, so I don't think the codebase have a consistency issue. Also Util usage is fairly common in Calcite code base, and it is kind of expected for people to look at that class for any utility method.

As for unit test, just reuse the same as previously? I think it should work as-is

@belugabehr
Copy link
Contributor Author

@laurentgo I had to take a bit of a different tact to implement it as you requested. Take a look. Thanks.

Copy link

@qinghui-xu qinghui-xu left a comment

Choose a reason for hiding this comment

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

It seems there is some code style issue.

};
}

/**

Choose a reason for hiding this comment

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

Code style: replace tab by using spaces.

@risdenk
Copy link
Contributor

risdenk commented Feb 27, 2019

Closing since JIRA closed

@risdenk risdenk closed this Feb 27, 2019
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.

4 participants