@@ -408,4 +408,52 @@ private List<Row> collect(DataFrameReader reader) {
408408 .orderBy ("_change_ordinal" , "_commit_snapshot_id" , "_change_type" , "id" )
409409 .collectAsList ();
410410 }
411+
412+ @ TestTemplate
413+ public void testChangelogViewOutsideTimeRange () {
414+ createTableWithDefaultRows ();
415+
416+ // Insert new records
417+ sql ("INSERT INTO %s VALUES (3, 'c')" , tableName );
418+ sql ("INSERT INTO %s VALUES (4, 'd')" , tableName );
419+
420+ Table table = validationCatalog .loadTable (tableIdent );
421+ Snapshot insertSnapshot = table .currentSnapshot ();
422+
423+ // Get timestamp after inserts but before our changelog window
424+ long beforeWindowTime = System .currentTimeMillis ();
425+
426+ // Small delay to ensure our timestamps are different
427+ try {
428+ Thread .sleep (100 );
429+ } catch (InterruptedException e ) {
430+ throw new RuntimeException ("Test interrupted" , e );
431+ }
432+
433+ long startTime = System .currentTimeMillis ();
434+ long endTime = startTime + 1000 ; // 1 second window
435+
436+ // Create changelog view for a time window after our inserts
437+ sql (
438+ "CALL %s.system.create_changelog_view("
439+ + " table => '%s', "
440+ + " options => map("
441+ + " 'start-timestamp', '%d',"
442+ + " 'end-timestamp', '%d'"
443+ + " ),"
444+ + " changelog_view => 'test_changelog_view'"
445+ + ")" ,
446+ catalogName , tableName , startTime , endTime );
447+
448+ // Query the changelog view
449+ List <Object []> results =
450+ sql (
451+ "SELECT * FROM test_changelog_view WHERE _change_type IN ('INSERT', 'DELETE') ORDER BY _change_ordinal" );
452+
453+ // Verify no changes are returned since our window is after the inserts
454+ assertThat (results ).as ("Num records must be zero" ).isEmpty ();
455+
456+ // Clean up the changelog view
457+ sql ("DROP VIEW IF EXISTS test_changelog_view" );
458+ }
411459}
0 commit comments