7575import java .util .ArrayList ;
7676import java .util .Arrays ;
7777import java .util .Collections ;
78- import java .util .Comparator ;
7978import java .util .HashMap ;
8079import java .util .List ;
8180import java .util .Map ;
@@ -1033,6 +1032,15 @@ void testListPartitionsFromFile() throws Exception {
10331032
10341033 @ Test
10351034 void testListPartitions () throws Exception {
1035+ innerTestListPartitions (true );
1036+ }
1037+
1038+ @ Test
1039+ void testListPartitionsNonMetastore () throws Exception {
1040+ innerTestListPartitions (false );
1041+ }
1042+
1043+ private void innerTestListPartitions (boolean metastore ) throws Exception {
10361044 if (!supportPartitions ()) {
10371045 return ;
10381046 }
@@ -1046,14 +1054,14 @@ void testListPartitions() throws Exception {
10461054 singletonMap ("dt" , "20250103" ));
10471055 Map [] sortedSpecs =
10481056 partitionSpecs .stream ()
1049- .sorted (Comparator . comparing ( i -> i .get ("dt" )))
1057+ .sorted (( o1 , o2 ) -> o2 . get ( "dt" ). compareTo ( o1 .get ("dt" )))
10501058 .toArray (Map []::new );
10511059
1052- String databaseName = "partitions_db" ;
1060+ String databaseName = "partitions_db" + metastore ;
10531061 Identifier identifier = Identifier .create (databaseName , "table" );
10541062 Schema schema =
10551063 Schema .newBuilder ()
1056- .option (METASTORE_PARTITIONED_TABLE .key (), "true" )
1064+ .option (METASTORE_PARTITIONED_TABLE .key (), Boolean . toString ( metastore ) )
10571065 .option (METASTORE_TAG_TO_PARTITION .key (), "dt" )
10581066 .column ("col" , DataTypes .INT ())
10591067 .column ("dt" , DataTypes .STRING ())
@@ -1073,7 +1081,12 @@ void testListPartitions() throws Exception {
10731081 }
10741082
10751083 List <Partition > restPartitions = restCatalog .listPartitions (identifier );
1076- assertThat (restPartitions .stream ().map (Partition ::spec )).containsExactly (sortedSpecs );
1084+ if (metastore ) {
1085+ assertThat (restPartitions .stream ().map (Partition ::spec )).containsExactly (sortedSpecs );
1086+ } else {
1087+ assertThat (restPartitions .stream ().map (Partition ::spec ))
1088+ .containsExactlyInAnyOrder (sortedSpecs );
1089+ }
10771090 }
10781091
10791092 @ Test
@@ -1123,34 +1136,31 @@ public void testListPartitionsPaged() throws Exception {
11231136 catalog .listPartitionsPaged (identifier , null , null , null );
11241137 Map [] sortedSpecs =
11251138 partitionSpecs .stream ()
1126- .sorted (Comparator . comparing ( i -> i .get ("dt" )))
1139+ .sorted (( o1 , o2 ) -> o2 . get ( "dt" ). compareTo ( o1 .get ("dt" )))
11271140 .toArray (Map []::new );
11281141 assertPagedPartitions (pagedPartitions , partitionSpecs .size (), sortedSpecs );
11291142
11301143 int maxResults = 2 ;
11311144 pagedPartitions = catalog .listPartitionsPaged (identifier , maxResults , null , null );
1132- assertPagedPartitions (
1133- pagedPartitions , maxResults , partitionSpecs .get (2 ), partitionSpecs .get (0 ));
1134- assertEquals ("dt=20250101" , pagedPartitions .getNextPageToken ());
1145+ assertPagedPartitions (pagedPartitions , maxResults , sortedSpecs [0 ], sortedSpecs [1 ]);
1146+ assertEquals (sortedSpecs [1 ].toString (), "{" + pagedPartitions .getNextPageToken () + "}" );
11351147
11361148 pagedPartitions =
11371149 catalog .listPartitionsPaged (
11381150 identifier , maxResults , pagedPartitions .getNextPageToken (), null );
1139- assertPagedPartitions (
1140- pagedPartitions , maxResults , partitionSpecs .get (1 ), partitionSpecs .get (5 ));
1141- assertEquals ("dt=20250103" , pagedPartitions .getNextPageToken ());
1151+ assertPagedPartitions (pagedPartitions , maxResults , sortedSpecs [2 ], sortedSpecs [3 ]);
1152+ assertEquals (sortedSpecs [3 ].toString (), "{" + pagedPartitions .getNextPageToken () + "}" );
11421153
11431154 pagedPartitions =
11441155 catalog .listPartitionsPaged (
11451156 identifier , maxResults , pagedPartitions .getNextPageToken (), null );
1146- assertPagedPartitions (
1147- pagedPartitions , maxResults , partitionSpecs .get (4 ), partitionSpecs .get (6 ));
1148- assertEquals ("dt=2025010_test" , pagedPartitions .getNextPageToken ());
1157+ assertPagedPartitions (pagedPartitions , maxResults , sortedSpecs [4 ], sortedSpecs [5 ]);
1158+ assertEquals (sortedSpecs [5 ].toString (), "{" + pagedPartitions .getNextPageToken () + "}" );
11491159
11501160 pagedPartitions =
11511161 catalog .listPartitionsPaged (
11521162 identifier , maxResults , pagedPartitions .getNextPageToken (), null );
1153- assertPagedPartitions (pagedPartitions , 1 , partitionSpecs . get ( 3 ) );
1163+ assertPagedPartitions (pagedPartitions , 1 , sortedSpecs [ 6 ] );
11541164 assertNull (pagedPartitions .getNextPageToken ());
11551165
11561166 maxResults = 8 ;
@@ -1168,11 +1178,11 @@ public void testListPartitionsPaged() throws Exception {
11681178 assertPagedPartitions (
11691179 pagedPartitions ,
11701180 5 ,
1171- partitionSpecs .get (0 ),
1172- partitionSpecs .get (1 ),
1173- partitionSpecs .get (5 ),
1181+ partitionSpecs .get (6 ),
11741182 partitionSpecs .get (4 ),
1175- partitionSpecs .get (6 ));
1183+ partitionSpecs .get (5 ),
1184+ partitionSpecs .get (1 ),
1185+ partitionSpecs .get (0 ));
11761186 assertNull (pagedPartitions .getNextPageToken ());
11771187
11781188 pagedPartitions = catalog .listPartitionsPaged (identifier , maxResults , null , "dt=2025010_%" );
@@ -1707,7 +1717,6 @@ protected boolean supportsFormatTable() {
17071717
17081718 @ Override
17091719 protected boolean supportPartitions () {
1710- // TODO support this
17111720 return true ;
17121721 }
17131722
0 commit comments