@@ -387,6 +387,121 @@ void globTraversalChecksIntermediateParentsAndEscapedDotSegments() {
387387 "viewfs://cluster/literal\\ name/file.csv" , properties ));
388388 }
389389
390+ @ Test
391+ void unguardedSameTableViewFsAliasUsesLazyRemoteDispatch () throws Exception {
392+ Map <String , String > properties = hdfs ("viewfs://cluster" );
393+ properties .put ("fs.viewfs.mounttable.cluster.link./a" , "viewfs://cluster/b" );
394+ properties .put ("fs.viewfs.mounttable.cluster.link./b" , "hdfs://nn/base" );
395+ Configuration runtime = defaults (properties );
396+ try (RemoteClients clients = new RemoteClients ()) {
397+ try (FileSystem outer = FileSystem .newInstance (URI .create ("viewfs://cluster" ), runtime )) {
398+ outer .getFileStatus (new Path ("/a/file.csv" ));
399+ Assertions .assertTrue (clients .events .contains ("stat:0:/base/file.csv" ));
400+ } finally {
401+ FileSystem .closeAll ();
402+ }
403+ clients .verifyClosedOnce ();
404+ }
405+ }
406+
407+ @ Test
408+ void guardedFiniteViewFsAliasesPreserveReadsWritesAndCleanup () throws Exception {
409+ String uri = "viewfs://cluster/a/file.csv" ;
410+ Map <String , String > properties = readProperties (uri );
411+ properties .put ("fs.defaultFS" , "viewfs://cluster" );
412+ properties .put ("fs.viewfs.mounttable.cluster.link./a" , "viewfs://cluster/b" );
413+ properties .put ("fs.viewfs.mounttable.cluster.link./b" , "hdfs://nn/base" );
414+ for (boolean enabled : new boolean [] {false , true }) {
415+ Config .enable_local_tvf = enabled ;
416+ Assertions .assertDoesNotThrow (() -> new HdfsTableValuedFunction (properties ));
417+ Assertions .assertDoesNotThrow (() -> HadoopTvfAdmission .checkReadDiscovery (
418+ "viewfs://cluster/a/*.csv" , properties ));
419+ }
420+ Config .enable_local_tvf = false ;
421+ Assertions .assertDoesNotThrow (() -> HadoopTvfAdmission .check (
422+ HadoopTvfAdmission .Access .NATIVE_WRITE , "/a/prefix_" , properties ));
423+ Assertions .assertDoesNotThrow (() -> HadoopTvfAdmission .check (
424+ HadoopTvfAdmission .Access .JAVA_DELETE , uri , properties ));
425+ try (RemoteClients clients = new RemoteClients ()) {
426+ try {
427+ Configuration read = TvfGuard .prepareJavaRead (defaults (properties ),
428+ new Path (uri ), TvfGuard .NATIVE_POLICY );
429+ try (FileSystem outer = FileSystem .newInstance (URI .create ("viewfs://cluster" ), read )) {
430+ outer .getFileStatus (new Path (uri ));
431+ Assertions .assertTrue (clients .events .stream ().anyMatch (
432+ event -> event .startsWith ("stat:" ) && event .endsWith (":/base/file.csv" )));
433+ }
434+ Configuration write = defaults (properties );
435+ overlay (write , HadoopTvfAdmission .protectNativeWrite ("/a/prefix_" , properties ));
436+ nativeRequest (write , "viewfs://cluster" , "/a/prefix_" );
437+ TvfGuard .clearNativeContext ();
438+ try (FileSystem outer = FileSystem .newInstance (URI .create ("viewfs://cluster" ), write )) {
439+ TvfGuard .Context context = TvfGuard .takeNativeContext ();
440+ Assertions .assertNotNull (context );
441+ Assertions .assertDoesNotThrow (() -> context .checkNative ("viewfs://cluster" , "/a/next_" ));
442+ }
443+ try (FileSystem outer = FileSystem .newInstance (URI .create ("viewfs://cluster" ),
444+ javaRequest (properties , HadoopTvfAdmission .Access .JAVA_DELETE , uri ))) {
445+ Assertions .assertTrue (outer .delete (new Path (uri ), true ));
446+ Assertions .assertTrue (clients .events .stream ().anyMatch (
447+ event -> event .startsWith ("delete:" ) && event .endsWith (":/base/file.csv" )));
448+ }
449+ } finally {
450+ FileSystem .closeAll ();
451+ }
452+ clients .verifyClosedOnce ();
453+ }
454+ }
455+
456+ @ Test
457+ void guardedViewFsAliasesStillRejectLocalTargetsAndCycles () throws Exception {
458+ String uri = "viewfs://cluster/a/file.csv" ;
459+ for (String target : new String [] {"file:///unused-local" , "viewfs://cluster/a" ,
460+ "viewfs://cluster/b/grow" }) {
461+ Map <String , String > properties = readProperties (uri );
462+ properties .put ("fs.defaultFS" , "viewfs://cluster" );
463+ properties .put ("fs.viewfs.mounttable.cluster.link./a" , "viewfs://cluster/b" );
464+ properties .put ("fs.viewfs.mounttable.cluster.link./b" , target );
465+ for (boolean enabled : new boolean [] {false , true }) {
466+ Config .enable_local_tvf = enabled ;
467+ Assertions .assertThrows (org .apache .doris .nereids .exceptions .AnalysisException .class ,
468+ () -> new HdfsTableValuedFunction (properties ), target );
469+ }
470+ Config .enable_local_tvf = false ;
471+ Assertions .assertThrows (org .apache .doris .nereids .exceptions .AnalysisException .class ,
472+ () -> HadoopTvfAdmission .check (HadoopTvfAdmission .Access .NATIVE_WRITE ,
473+ "/a/prefix_" , properties ), target );
474+ Assertions .assertThrows (org .apache .doris .nereids .exceptions .AnalysisException .class ,
475+ () -> HadoopTvfAdmission .check (HadoopTvfAdmission .Access .JAVA_DELETE , uri , properties ), target );
476+ Configuration runtime = defaults (properties );
477+ Assertions .assertThrows (IOException .class , () -> TvfGuard .prepareJavaRead (
478+ runtime , new Path (uri ), TvfGuard .NATIVE_POLICY ), target );
479+ runtime .set (TvfGuard .POLICY_KEY , TvfGuard .NATIVE_WRITE_POLICY );
480+ nativeRequest (runtime , "viewfs://cluster" , "/a/prefix_" );
481+ try (RemoteClients clients = new RemoteClients ()) {
482+ Assertions .assertThrows (IOException .class ,
483+ () -> FileSystem .newInstance (URI .create ("viewfs://cluster" ), runtime ), target );
484+ Assertions .assertTrue (clients .clients .isEmpty ());
485+ }
486+ }
487+ }
488+
489+ @ Test
490+ void finiteSameTableAliasChainsRetainTheDelegationDepthBound () {
491+ Map <String , String > properties = hdfs ("viewfs://cluster" );
492+ for (int i = 0 ; i < 31 ; i ++) {
493+ properties .put ("fs.viewfs.mounttable.cluster.link./a" + i , "viewfs://cluster/a" + (i + 1 ));
494+ }
495+ properties .put ("fs.viewfs.mounttable.cluster.link./a31" , "hdfs://nn/base" );
496+ Assertions .assertDoesNotThrow (() -> HadoopTvfAdmission .check (
497+ HadoopTvfAdmission .Access .JAVA_DELETE , "viewfs://cluster/a0/file.csv" , properties ));
498+ properties .put ("fs.viewfs.mounttable.cluster.link./a31" , "viewfs://cluster/a32" );
499+ properties .put ("fs.viewfs.mounttable.cluster.link./a32" , "hdfs://nn/base" );
500+ Assertions .assertThrows (org .apache .doris .nereids .exceptions .AnalysisException .class ,
501+ () -> HadoopTvfAdmission .check (HadoopTvfAdmission .Access .JAVA_DELETE ,
502+ "viewfs://cluster/a0/file.csv" , properties ));
503+ }
504+
390505 @ Test
391506 void guardedJuiceFsRequiresProvenRemoteBackingStore () throws Exception {
392507 for (boolean enabled : new boolean [] {false , true }) {
0 commit comments