Xuanwo commented on code in PR #5617:
URL: https://github.com/apache/opendal/pull/5617#discussion_r1993263552


##########
core/src/services/hdfs_native/reader.rs:
##########
@@ -15,23 +15,58 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use futures::StreamExt;
 use hdfs_native::file::FileReader;
 
 use crate::raw::*;
+use crate::services::hdfs_native::error::parse_hdfs_error;
 use crate::*;
 
 pub struct HdfsNativeReader {
-    _f: FileReader,
+    f: FileReader,
+    offset: usize,
+    read: usize,
+    size: usize,
+    buf_size: usize,
+    buf: Buffer,
 }
 
 impl HdfsNativeReader {
-    pub fn new(f: FileReader) -> Self {
-        HdfsNativeReader { _f: f }
+    pub fn new(f: FileReader, offset: usize, size: usize) -> Self {
+        HdfsNativeReader {
+            f,
+            offset,
+            read: 0,
+            size,
+            // Use 2 MiB as default value.
+            buf_size: 2 * 1024 * 1024,
+            buf: Buffer::new(),
+        }
     }
 }
 
 impl oio::Read for HdfsNativeReader {
     async fn read(&mut self) -> Result<Buffer> {
-        todo!()
+        if self.read >= self.size {
+            return Ok(Buffer::new());
+        }
+
+        if self.buf.is_empty() {

Review Comment:
   I didn't get why we need this. Can we store the stream directly and avoid 
copying them?



##########
core/src/services/hdfs_native/writer.rs:
##########
@@ -15,28 +15,44 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use hdfs_native::file::FileWriter;
-
-use crate::raw::oio;
+use crate::raw::*;
+use crate::services::hdfs_native::error::parse_hdfs_error;
 use crate::*;
-
+use hdfs_native::file::FileWriter;
+use log::error;
 pub struct HdfsNativeWriter {
-    _f: FileWriter,
+    f: FileWriter,
+    size: u64,
 }
 
 impl HdfsNativeWriter {
-    pub fn new(f: FileWriter) -> Self {
-        HdfsNativeWriter { _f: f }
+    pub fn new(f: FileWriter, initial_size: u64) -> Self {
+        HdfsNativeWriter {
+            f,
+            size: initial_size,
+        }
     }
 }
 
 impl oio::Write for HdfsNativeWriter {
-    async fn write(&mut self, _bs: Buffer) -> Result<()> {
-        todo!()
+    async fn write(&mut self, mut buf: Buffer) -> Result<()> {
+        let len = buf.len() as u64;
+
+        for bs in buf.by_ref() {
+            self.f.write(bs).await.map_err(|e| {
+                error!("write error: {:?}", e);

Review Comment:
   Please remove this line.



##########
.github/services/hdfs_native/hdfs_native_cluster/action.yml:
##########
@@ -0,0 +1,39 @@
+# 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.
+
+name: hdfs_native_cluster
+description: 'Behavior test for hdfs native cluster'
+
+runs:
+  using: "composite"
+  steps:
+    - name: Setup HDFS Native cluster
+      shell: bash
+      working-directory: fixtures/hdfs_native
+      run: docker compose -f docker-compose-hdfs-native-cluster.yml up -d 
--wait
+    - name: Setup hadoop
+      uses: ./.github/actions/setup-hadoop

Review Comment:
   We don't need to set hadoop since we will connect them natively.



##########
core/src/services/hdfs_native/lister.rs:
##########
@@ -15,28 +15,68 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use std::sync::Arc;
-
+use crate::raw::build_rel_path;
 use crate::raw::oio;
-use crate::raw::oio::Entry;
-use crate::*;
+use crate::raw::parse_datetime_from_from_timestamp_millis;
+use crate::services::hdfs_native::error::parse_hdfs_error;
+use crate::EntryMode;
+use crate::Metadata;
+use crate::Result;
+use hdfs_native::client::ListStatusIterator;
 
 pub struct HdfsNativeLister {
-    _path: String,
-    _client: Arc<hdfs_native::Client>,
+    root: String,
+    iter: ListStatusIterator,
+    current_path: Option<String>,
+    iter_to_end: bool,
 }
 
+unsafe impl Sync for HdfsNativeLister {}

Review Comment:
   Can we avoid this?



##########
core/src/services/hdfs_native/backend.rs:
##########
@@ -240,16 +279,61 @@ impl Access for HdfsNativeBackend {
 
     async fn list(&self, path: &str, _args: OpList) -> Result<(RpList, 
Self::Lister)> {
         let p = build_rooted_abs_path(&self.root, path);
-        let l = HdfsNativeLister::new(p, self.client.clone());
-        Ok((RpList::default(), Some(l)))
+
+        let isdir = match self.client.get_file_info(&p).await {
+            Ok(status) => status.isdir,
+            Err(err) => {
+                return match &err {
+                    HdfsError::FileNotFound(_) => Ok((RpList::default(), 
None)),
+                    _ => Err(parse_hdfs_error(err)),
+                };
+            }
+        };
+        let current_path = if isdir {
+            if !path.ends_with("/") {
+                Some(path.to_string() + "/")
+            } else {
+                Some(path.to_string())
+            }
+        } else {
+            None
+        };
+
+        let iter = self.client.list_status_iter(&p, false);

Review Comment:
   Please call list inside `Lister`.



##########
.github/services/hdfs_native/hdfs_native_cluster/action.yml:
##########
@@ -0,0 +1,39 @@
+# 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.
+
+name: hdfs_native_cluster
+description: 'Behavior test for hdfs native cluster'
+
+runs:
+  using: "composite"
+  steps:
+    - name: Setup HDFS Native cluster
+      shell: bash
+      working-directory: fixtures/hdfs_native

Review Comment:
   We can use hdfs's fixtures directly.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to