Skip to content

Conversation

@linhuih
Copy link
Contributor

@linhuih linhuih commented Nov 11, 2025

Supports adding fields to existing indices in Elasticsearch during online operations

@codecov
Copy link

codecov bot commented Nov 11, 2025

Codecov Report

❌ Patch coverage is 97.98658% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.25%. Comparing base (662ca1d) to head (f4027f7).

Files with missing lines Patch % Lines
sql/engines/elasticsearch.py 90.62% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3079      +/-   ##
==========================================
+ Coverage   79.05%   79.25%   +0.20%     
==========================================
  Files         131      131              
  Lines       19049    19189     +140     
==========================================
+ Hits        15059    15209     +150     
+ Misses       3990     3980      -10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hhyo hhyo requested a review from Copilot November 11, 2025 22:35
Copilot finished reviewing on behalf of hhyo November 11, 2025 22:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for updating Elasticsearch index field mappings via the _mapping API endpoint during online operations. This enables users to add new fields to existing indices without downtime.

  • Adds validation logic in execute_check to ensure PUT requests to _mapping contain a properties field
  • Implements __put_mapping method to handle mapping updates via conn.indices.put_mapping
  • Updates error messages and the list of supported API endpoints to include _mapping

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
sql/engines/elasticsearch.py Adds _mapping endpoint support with validation logic in execute_check, implements __put_mapping execution method, and updates supported endpoint list
sql/engines/test_elasticsearch.py Adds comprehensive test coverage for _mapping API including validation tests, successful execution, error handling, and edge cases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Collaborator

@LeoQuote LeoQuote left a comment

Choose a reason for hiding this comment

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

程序主体没啥问题, 看一下风格问题

sql=doc.sql,
)
else:
if is_pass is False:
Copy link
Collaborator

Choose a reason for hiding this comment

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

像这种语句可以简洁的写成

Suggested change
if is_pass is False:
if not is_pass:

Comment on lines +683 to 684
if is_pass is False:
is_pass = True
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if is_pass is False:
is_pass = True
is_pass = True

这个判断在我看来没有意义, 你看看这样简单写行不行

)
else:
if is_pass == False:
if is_pass is False:
Copy link
Collaborator

Choose a reason for hiding this comment

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

@copilot 这里的 is_pass 有点过于简单, 能否帮忙换一个变量名让他表意更明确

@LeoQuote LeoQuote requested a review from Copilot November 12, 2025 03:51
Copilot finished reviewing on behalf of LeoQuote November 12, 2025 03:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

response = conn.indices.put_mapping(
index=doc.index_name, body=doc.doc_data_body
)
successful_count = response.get("_shards", {}).get("successful", None)
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

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

The variable successful_count is not initialized when an exception occurs and the condition 'index_not_found_exception' in error_message.lower() is False. This will cause a NameError when trying to use it in the return statement at line 972. The variable should be initialized before the try block, similar to other methods like __update and __create_index.

Copilot uses AI. Check for mistakes.
index=doc.index_name, body=doc.doc_data_body
)
successful_count = response.get("_shards", {}).get("successful", None)
response_str = str(response)
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

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

The variable response_str is not initialized when an exception occurs and the condition 'index_not_found_exception' in error_message.lower() is False. This will cause a NameError when trying to use it in the return statement at line 970. The variable should be initialized before the try block.

Copilot uses AI. Check for mistakes.
mockElasticsearch.return_value = mock_conn

workflow = Mock()
workflow.sqlworkflowcontent.sql_content = 'PUT /nonexistent_index/_mapping {"properties": {"new_field": {"type": "text"}}}'
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

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

[nitpick] This line exceeds typical line length conventions (appears to be >100 characters). Consider breaking the SQL string into a multi-line format for better readability, consistent with the formatting used in other test methods like test_execute_workflow_put_mapping_success.

Suggested change
workflow.sqlworkflowcontent.sql_content = 'PUT /nonexistent_index/_mapping {"properties": {"new_field": {"type": "text"}}}'
workflow.sqlworkflowcontent.sql_content = (
'PUT /nonexistent_index/_mapping {"properties": {"new_field": {"type": "text"}}}'
)

Copilot uses AI. Check for mistakes.
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