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

[CALCITE-6386] NPE when using ES adapter with model.json and no specified username, password or pathPrefix #3775

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

guluo2016
Copy link

Details see: CALCITE-6386

@guluo2016 guluo2016 force-pushed the es-apater-model-json branch 2 times, most recently from aeb19d5 to e481252 Compare April 27, 2024 14:53
*/
@ResourceLock(value = "elasticsearch-scrolls", mode = ResourceAccessMode.READ)
public class ElasticSearchAdapterFromModelFileTest {
public static final EmbeddedElasticsearchPolicy NODE = EmbeddedElasticsearchPolicy.create();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you include this in an existing test Java file. Too verbose.

Copy link
Author

Choose a reason for hiding this comment

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

OK,I will add these tests to ElasticSearchAdapterTest and update it.

.put("transport.tcp.port", 0)
.put("http.port", 0)
.put("transport.tcp.port", 9300)
.put("http.port", 9200)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why make this change? Back it out.

Copy link
Author

Choose a reason for hiding this comment

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

I will discard this changes,thanks a lot.

"schemas": [
{
"type": "custom",
"name": "elasticsearch",
Copy link
Contributor

Choose a reason for hiding this comment

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

No copyright header. No comments explaining its purpose. Looks benign but is broken.

Would be better to just remove it, if the test can be written without it.

try {
CalciteAssert.that()
.with(MODEL)
.query(String.format("select * from \"%s\"", tableName))
Copy link
Contributor

Choose a reason for hiding this comment

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

Test should fail if no exception is thrown.

.returnsCount(0);
} catch (Exception e) {
String message = e.getMessage();
Assertions.assertTrue(message.contains(String.format("Object '%s' not found", tableName)));
Copy link
Contributor

Choose a reason for hiding this comment

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

Use assertThat not assertTrue

List cacheKey = Arrays.asList(hosts, pathPrefix, username, password)
.stream()
.filter(Objects::nonNull)
.collect(toImmutableList());
Copy link
Contributor

Choose a reason for hiding this comment

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

(X, null, Y) will have the same cache key as (null, X, Y). This is a security flaw.

Suggest using an immutable map as cache key.

Copy link
Author

Choose a reason for hiding this comment

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

Make sense. I will update it, thanks.

Copy link

sonarcloud bot commented Apr 28, 2024

@guluo2016 guluo2016 requested a review from julianhyde May 13, 2024 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants