You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "zhangbutao (via GitHub)" <gi...@apache.org> on 2024/06/05 16:03:52 UTC
[PR] Hive: Return new scan after applying column project parameter [iceberg]
zhangbutao opened a new pull request, #10449:
URL: https://github.com/apache/iceberg/pull/10449
1. Shoud return a new scan applying column project parameter, Otherwise it doesn't make any sense
2. scan.project() and scan.select() can not be specified at the same time
Check this:
https://github.com/apache/iceberg/pull/1353/files#diff-a94dee2a22a2890689a84529a978a769bdc3b084f35d79caf9608d49b2e1cc1b
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Return new scan after applying column project parameter [iceberg]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #10449:
URL: https://github.com/apache/iceberg/pull/10449#issuecomment-2471993676
This pull request has been closed due to lack of activity. This is not a judgement on the merit of the PR in any way. It is just a way of keeping the PR queue manageable. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Return new scan after applying column project parameter [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on PR #10449:
URL: https://github.com/apache/iceberg/pull/10449#issuecomment-2150699009
@zhangbutao: Could you please provide a test case which fails without the patch and runs correctly with the patch?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Return new scan after applying column project parameter [iceberg]
Posted by "zhangbutao (via GitHub)" <gi...@apache.org>.
zhangbutao commented on code in PR #10449:
URL: https://github.com/apache/iceberg/pull/10449#discussion_r1635749793
##########
mr/src/main/java/org/apache/iceberg/mr/mapreduce/IcebergInputFormat.java:
##########
@@ -125,11 +125,9 @@ public List<InputSplit> getSplits(JobContext context) {
}
String schemaStr = conf.get(InputFormatConfig.READ_SCHEMA);
if (schemaStr != null) {
- scan.project(SchemaParser.fromJson(schemaStr));
- }
- String[] selectedColumns = conf.getStrings(InputFormatConfig.SELECTED_COLUMNS);
- if (selectedColumns != null) {
- scan.select(selectedColumns);
+ scan = scan.project(SchemaParser.fromJson(schemaStr));
+ } else if (conf.getStrings(InputFormatConfig.SELECTED_COLUMNS) != null) {
Review Comment:
BTW, It doesn't make any difference whether the scan has projected columns or not as on hive side we use the conf to propagate the projected columns. Check this comment https://github.com/apache/hive/pull/5282#issuecomment-2154202895
But we need care that if we allow user to set the projected columns, mainly means `iceberg.mr.read.schema`, as it can be propagated by the conf to be used by the iceberg reader.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Return new scan after applying column project parameter [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on code in PR #10449:
URL: https://github.com/apache/iceberg/pull/10449#discussion_r1632746388
##########
mr/src/test/java/org/apache/iceberg/mr/TestIcebergInputFormats.java:
##########
@@ -234,6 +234,8 @@ public void testProjection() throws Exception {
Schema projection = TypeUtil.select(SCHEMA, ImmutableSet.of(1));
builder.project(projection);
+ // project() is the first to be applied on scan, so the select() won't take effect.
+ builder.select("id");
Review Comment:
@zhangbutao: That test would be great - it would test if setting `select` and `project` both working!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Return new scan after applying column project parameter [iceberg]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #10449: Hive: Return new scan after applying column project parameter
URL: https://github.com/apache/iceberg/pull/10449
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Return new scan after applying column project parameter [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on code in PR #10449:
URL: https://github.com/apache/iceberg/pull/10449#discussion_r1635167684
##########
mr/src/main/java/org/apache/iceberg/mr/mapreduce/IcebergInputFormat.java:
##########
@@ -125,11 +125,9 @@ public List<InputSplit> getSplits(JobContext context) {
}
String schemaStr = conf.get(InputFormatConfig.READ_SCHEMA);
if (schemaStr != null) {
- scan.project(SchemaParser.fromJson(schemaStr));
- }
- String[] selectedColumns = conf.getStrings(InputFormatConfig.SELECTED_COLUMNS);
- if (selectedColumns != null) {
- scan.select(selectedColumns);
+ scan = scan.project(SchemaParser.fromJson(schemaStr));
+ } else if (conf.getStrings(InputFormatConfig.SELECTED_COLUMNS) != null) {
Review Comment:
This is a questionable decision in my mind.
We allow the user to set columns and schema, but behind the scenes we decide to use only one of them?
If this would be a new code, I would ask for a validation, and we should throw an exception if both of them are set.
OTOH it is a bit questionable what we should do now, as some users might expect to get away with setting both, as they were ignored before.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Return new scan after applying column project parameter [iceberg]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #10449:
URL: https://github.com/apache/iceberg/pull/10449#issuecomment-2458451811
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Return new scan after applying column project parameter [iceberg]
Posted by "zhangbutao (via GitHub)" <gi...@apache.org>.
zhangbutao commented on code in PR #10449:
URL: https://github.com/apache/iceberg/pull/10449#discussion_r1629227339
##########
mr/src/test/java/org/apache/iceberg/mr/TestIcebergInputFormats.java:
##########
@@ -234,6 +234,8 @@ public void testProjection() throws Exception {
Schema projection = TypeUtil.select(SCHEMA, ImmutableSet.of(1));
builder.project(projection);
+ // project() is the first to be applied on scan, so the select() won't take effect.
+ builder.select("id");
Review Comment:
@pvary I tried to add a better ut to verify this change, but i found it is a little difficult.
I can not get the iceberg `scan` which is initialized in `IcebergInputFormat `to check whether the `project()` or `select()` is applied or not.
So i think we can check this change like this:
1) It is obvious that we need to use the new `scan` after applying `project()` or `select()`. Right?
```
@@ -125,11 +125,11 @@ public class IcebergInputFormat<T> extends InputFormat<Void, T> {
}
String schemaStr = conf.get(InputFormatConfig.READ_SCHEMA);
if (schemaStr != null) {
- scan.project(SchemaParser.fromJson(schemaStr));
+ scan = scan.project(SchemaParser.fromJson(schemaStr));
}
String[] selectedColumns = conf.getStrings(InputFormatConfig.SELECTED_COLUMNS);
if (selectedColumns != null) {
- scan.select(selectedColumns);
+ scan = scan.select(selectedColumns);
}
```
After using the new scan, we can get execption when running the test:
`java.lang.IllegalStateException: Cannot select columns when projection schema is set`, the exception is the same as https://github.com/apache/iceberg/pull/1353/files#diff-a94dee2a22a2890689a84529a978a769bdc3b084f35d79caf9608d49b2e1cc1b
```
@TestTemplate
public void testProjection() throws Exception {
helper.createTable();
List<Record> inputRecords = helper.generateRandomRecords(1, 0L);
helper.appendToTable(Row.of("2020-03-20", 0), inputRecords);
Schema projection = TypeUtil.select(SCHEMA, ImmutableSet.of(1));
builder.project(projection);
// project() is the first to be applied on scan, so the select() won't take effect.
builder.select("id");
List<Record> outputRecords = testInputFormat.create(builder.conf()).getRecords();
assertThat(outputRecords).hasSameSizeAs(inputRecords);
assertThat(outputRecords.get(0).struct()).isEqualTo(projection.asStruct());
}
```
2) After using the new scan, we **can not be specified at the same time**. So this change is the final fix.
Do you have any other ideas to write the test?
Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Return new scan after applying column project parameter [iceberg]
Posted by "zhangbutao (via GitHub)" <gi...@apache.org>.
zhangbutao commented on code in PR #10449:
URL: https://github.com/apache/iceberg/pull/10449#discussion_r1635743782
##########
mr/src/main/java/org/apache/iceberg/mr/mapreduce/IcebergInputFormat.java:
##########
@@ -125,11 +125,9 @@ public List<InputSplit> getSplits(JobContext context) {
}
String schemaStr = conf.get(InputFormatConfig.READ_SCHEMA);
if (schemaStr != null) {
- scan.project(SchemaParser.fromJson(schemaStr));
- }
- String[] selectedColumns = conf.getStrings(InputFormatConfig.SELECTED_COLUMNS);
- if (selectedColumns != null) {
- scan.select(selectedColumns);
+ scan = scan.project(SchemaParser.fromJson(schemaStr));
+ } else if (conf.getStrings(InputFormatConfig.SELECTED_COLUMNS) != null) {
Review Comment:
@pvary Your comment made me think further. :)
> We allow the user to set columns and schema, but behind the scenes we decide to use only one of them?
I don't think we should allow user to set the` projected columns`, as this is a internal query optimization in engine like hive/spark. This conf related to `projected columns `should not be exposed to the end user.
So, before this comment, what i have said was based on that user can not set the conf about ` projected columns`.
In hive, the conf related to iceberg ` projected columns` are `iceberg.mr.read.schema` & `iceberg.mr.selected.columns`, and `iceberg.mr.selected.columns` will be always overwritten by `hive.io.file.readcolumn.names`, Check https://github.com/apache/iceberg/blob/282fa73b2c2b51b1d519a91e8bb05b2d2bdf3cf4/mr/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergInputFormat.java#L99-L100 . And `hive.io.file.readcolumn.names` starts with prefix **hive** but not a valid propertity in `HiveConf.java`, so user can not set the value of `hive.io.file.readcolumn.names`.
https://github.com/apache/hive/blob/33cadc5b498b57f779cddc9bf4e3f8aef2d9f6dc/ql/src/java/org/apache/hadoop/hive/ql/processors/SetProcessor.java#L254-L255
```
0: jdbc:hive2://127.0.0.1:10000/default> set hive.io.file.readcolumn.names=id;
Error: Error while processing statement: hive configuration hive.io.file.readcolumn.names does not exists. (state=42000,code=1)
```
That is to say, user can not change the vlaue of `hive.io.file.readcolumn.names` & `iceberg.mr.selected.columns`, and i think this behavior is reasonable.
For `iceberg.mr.read.schema` which is used by project shcemas, hive does not actually set the value internally & always null. So, if user don't set & change its value, hive will never use it.
But now, your comments made me think that user may can change the value of `iceberg.mr.read.schema`. if user set the value of `iceberg.mr.read.schema`, it can be changed by normal and will lead to the side effect when initializing iceberg reader(`iceberg.mr.read.schema` is chosen as a priority over `iceberg.mr.selected.columns`), check: https://github.com/apache/iceberg/blob/282fa73b2c2b51b1d519a91e8bb05b2d2bdf3cf4/mr/src/main/java/org/apache/iceberg/mr/mapreduce/IcebergInputFormat.java#L490
**The last, what i want to say is that we should not allow to set the conf related project columns.** I think we can remove the use of `iceberg.mr.read.schema` as it actually not be used by hive internal & it can lead to side effect.
If you have any other good suggesstion, please comment here. Many thanks.
Also cc @deniskuzZ
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Return new scan after applying column project parameter [iceberg]
Posted by "zhangbutao (via GitHub)" <gi...@apache.org>.
zhangbutao commented on PR #10449:
URL: https://github.com/apache/iceberg/pull/10449#issuecomment-2151496203
> @zhangbutao: Could you please provide a test case which fails without the patch and runs correctly with the patch?
@pvary Thanks for you comment. Actually, there are no failed tests without this change. I am not sure how to add the test & also think no need add the test.
1. First, `scan.project() `& `scan.select` is a optimization for reducing some column scanning, before this change, we never use the new scan but this won't result in failure; after the change, we use the new scan which can optimize some else stuff.
2. Second, `scan.project()` & `scan.select` can not be specified at the same time, see this test
https://github.com/apache/iceberg/pull/1353/files#diff-a94dee2a22a2890689a84529a978a769bdc3b084f35d79caf9608d49b2e1cc1b
Before this change, `scan.project()` is never used in hive implementation, and you can check the `InputFormatConfig.READ_SCHEMA` which never been assigned a value, so we nerver get a failed test when `scan.project() `& `scan.select` both exist.
Thanks. :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Return new scan after applying column project parameter [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on PR #10449:
URL: https://github.com/apache/iceberg/pull/10449#issuecomment-2151612132
> I am not sure how to add the test & also think no need add the test.
I disagree with you here because of 2 reasons:
1. If there is no tests, then how can we be sure that future changes around the code doesn't revert back your fix?
2. If we don't have tests executing the code path, we can't be sure that the code is working as expected
Minimally we need to be sure that both codepath is called at least once during the tests. Could you please provide an example which tests executes the following line:
```
scan = scan.project(SchemaParser.fromJson(schemaStr));
```
also, which test executes this line:
```
scan = scan.select(conf.getStrings(InputFormatConfig.SELECTED_COLUMNS));
```
You might be able to create our own test to verify that the functions are called by adding a new test which tries to set both `project` and `select`, and fails because of the line you have linked.
If we verified that the lines are called in our existing tests, and we have new test which verifies that the values are set on the scan then I'm fairly confident that we will not have regression later around the codepaths you're fixing now.
Thanks for your work!
Peter
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Return new scan after applying column project parameter [iceberg]
Posted by "zhangbutao (via GitHub)" <gi...@apache.org>.
zhangbutao commented on code in PR #10449:
URL: https://github.com/apache/iceberg/pull/10449#discussion_r1634220405
##########
mr/src/test/java/org/apache/iceberg/mr/TestIcebergInputFormats.java:
##########
@@ -234,6 +234,8 @@ public void testProjection() throws Exception {
Schema projection = TypeUtil.select(SCHEMA, ImmutableSet.of(1));
builder.project(projection);
+ // project() is the first to be applied on scan, so the select() won't take effect.
+ builder.select("id");
Review Comment:
The final test is already here https://github.com/apache/iceberg/pull/10449/commits/5c695e504cac1b6347a56a05b7407818aa967a17, what else do I need to do?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Hive: Return new scan after applying column project parameter [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on code in PR #10449:
URL: https://github.com/apache/iceberg/pull/10449#discussion_r1636140730
##########
mr/src/main/java/org/apache/iceberg/mr/mapreduce/IcebergInputFormat.java:
##########
@@ -125,11 +125,9 @@ public List<InputSplit> getSplits(JobContext context) {
}
String schemaStr = conf.get(InputFormatConfig.READ_SCHEMA);
if (schemaStr != null) {
- scan.project(SchemaParser.fromJson(schemaStr));
- }
- String[] selectedColumns = conf.getStrings(InputFormatConfig.SELECTED_COLUMNS);
- if (selectedColumns != null) {
- scan.select(selectedColumns);
+ scan = scan.project(SchemaParser.fromJson(schemaStr));
+ } else if (conf.getStrings(InputFormatConfig.SELECTED_COLUMNS) != null) {
Review Comment:
Don't forget that this is not Hive only code. Originally it was intended for reading the Iceberg table through MR jobs. While this might not be the most common use, we should not forget about this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org