You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2020/01/15 17:35:52 UTC

[GitHub] [incubator-iceberg] rdblue commented on a change in pull request #721: Add PreferredLocations support for Iceberg Spark Source

rdblue commented on a change in pull request #721: Add PreferredLocations support for Iceberg Spark Source
URL: https://github.com/apache/incubator-iceberg/pull/721#discussion_r367011590
 
 

 ##########
 File path: spark/src/main/java/org/apache/iceberg/spark/source/Reader.java
 ##########
 @@ -308,6 +332,29 @@ private ReadTask(CombinedScanTask task, String tableSchemaString, String expecte
         encryptionManager.value(), caseSensitive);
     }
 
+    @Override
+    public String[] preferredLocations() {
+      if (!localityPreferred) {
+        return new String[0];
+      }
+
+      Configuration conf = SparkSession.active().sparkContext().hadoopConfiguration();
+      Set<String> locations = Sets.newHashSet();
+      for (FileScanTask f : task.files()) {
+        Path path = new Path(f.file().path().toString());
+        try {
+          FileSystem fs = path.getFileSystem(conf);
+          for (BlockLocation b : fs.getFileBlockLocations(path, f.start(), f.length())) {
+            locations.addAll(Arrays.asList(b.getHosts()));
+          }
+        } catch (IOException ioe) {
+          LOG.warn("Failed to get block locations for path {}", path, ioe);
 
 Review comment:
   I think I agree with the existing warn behavior. If we can't get locality info from the FS it shouldn't fail the job. It is a preference, not a requirement right?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org