You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "fansehep (via GitHub)" <gi...@apache.org> on 2023/10/09 10:21:39 UTC
[PR] chore: add csv example [arrow-rs]
fansehep opened a new pull request, #4904:
URL: https://github.com/apache/arrow-rs/pull/4904
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes https://github.com/apache/arrow-rs/issues/1613
# Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
# What changes are included in this PR?
add a example for arrow-csv.
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
# Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!---
If there are any breaking changes to public APIs, please add the `breaking change` label.
-->
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] chore: add csv example [arrow-rs]
Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4904:
URL: https://github.com/apache/arrow-rs/pull/4904#discussion_r1350212242
##########
arrow-csv/examples/README.md:
##########
@@ -0,0 +1,21 @@
+<!---
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+# Examples
+- [`csv_calculation.rs`](csv_calculation.rs): simple use the csv API to calcuate.
Review Comment:
```suggestion
- [`csv_calculation.rs`](csv_calculation.rs): performs a simple calculation using the CSV reader
```
##########
arrow-csv/examples/csv_calculation.rs:
##########
@@ -0,0 +1,62 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use arrow_array::Int16Array;
+use arrow_csv::ReaderBuilder;
+
+use arrow_schema::{DataType, Field, Schema};
+use std::fs::File;
+use std::sync::Arc;
+
+fn main() {
+ // read csv from file
+ let file = File::open("arrow-csv/test/data/example.csv").unwrap();
+ let csv_schema = Schema::new(vec![
+ Field::new("c1", DataType::Int16, true),
+ Field::new("c2", DataType::Float32, true),
+ Field::new("c3", DataType::Utf8, true),
+ Field::new("c4", DataType::Boolean, true),
+ ]);
+ let mut reader = ReaderBuilder::new(Arc::new(csv_schema))
+ .has_header(true)
+ .build(file)
+ .unwrap();
+
+ match reader.next() {
+ Some(e) => match e {
+ Ok(s) => {
+ // get the column(0) max value
+ println!(
+ "max value column(0): {:?}",
+ s.column(0)
+ .as_any()
+ .downcast_ref::<Int16Array>()
+ .unwrap()
+ .iter()
+ .max()
+ .unwrap()
+ );
Review Comment:
```suggestion
let col = s.column(0).as_primitive::<Int16Type>();
let max = col.iter().max().flatten();
println!("max value column(0): {max:?}");
```
With the necessary additional imports
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] chore: add csv example [arrow-rs]
Posted by "fansehep (via GitHub)" <gi...@apache.org>.
fansehep commented on code in PR #4904:
URL: https://github.com/apache/arrow-rs/pull/4904#discussion_r1350120212
##########
arrow-csv/examples/csv_calculation.rs:
##########
@@ -0,0 +1,62 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use arrow_array::Int16Array;
+use arrow_csv::ReaderBuilder;
+
+use arrow_schema::{DataType, Field, Schema};
+use std::fs::File;
+use std::sync::Arc;
+
+fn main() {
+ // read csv from file
+ let file = File::open("arrow-csv/test/data/example.csv").unwrap();
Review Comment:
Maybe I think don't need create a new file.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] chore: add csv example [arrow-rs]
Posted by "fansehep (via GitHub)" <gi...@apache.org>.
fansehep commented on code in PR #4904:
URL: https://github.com/apache/arrow-rs/pull/4904#discussion_r1350245561
##########
arrow-csv/examples/README.md:
##########
@@ -0,0 +1,21 @@
+<!---
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+# Examples
+- [`csv_calculation.rs`](csv_calculation.rs): simple use the csv API to calcuate.
Review Comment:
Down. Good iead. 😄
##########
arrow-csv/examples/README.md:
##########
@@ -0,0 +1,21 @@
+<!---
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+# Examples
+- [`csv_calculation.rs`](csv_calculation.rs): simple use the csv API to calcuate.
Review Comment:
Down. Good iead. 😄
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] chore: add csv example [arrow-rs]
Posted by "fansehep (via GitHub)" <gi...@apache.org>.
fansehep commented on code in PR #4904:
URL: https://github.com/apache/arrow-rs/pull/4904#discussion_r1350245561
##########
arrow-csv/examples/README.md:
##########
@@ -0,0 +1,21 @@
+<!---
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+# Examples
+- [`csv_calculation.rs`](csv_calculation.rs): simple use the csv API to calcuate.
Review Comment:
Done. Good iead. 😄
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] chore: add csv example [arrow-rs]
Posted by "fansehep (via GitHub)" <gi...@apache.org>.
fansehep commented on code in PR #4904:
URL: https://github.com/apache/arrow-rs/pull/4904#discussion_r1350120212
##########
arrow-csv/examples/csv_calculation.rs:
##########
@@ -0,0 +1,62 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use arrow_array::Int16Array;
+use arrow_csv::ReaderBuilder;
+
+use arrow_schema::{DataType, Field, Schema};
+use std::fs::File;
+use std::sync::Arc;
+
+fn main() {
+ // read csv from file
+ let file = File::open("arrow-csv/test/data/example.csv").unwrap();
Review Comment:
Maybe I thnk don't need create a new file.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] chore: add csv example [arrow-rs]
Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold merged PR #4904:
URL: https://github.com/apache/arrow-rs/pull/4904
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org