45
45
import org .apache .paimon .rest .requests .CreateDatabaseRequest ;
46
46
import org .apache .paimon .rest .requests .CreatePartitionsRequest ;
47
47
import org .apache .paimon .rest .requests .CreateTableRequest ;
48
+ import org .apache .paimon .rest .requests .CreateViewRequest ;
48
49
import org .apache .paimon .rest .requests .DropPartitionsRequest ;
49
50
import org .apache .paimon .rest .requests .MarkDonePartitionsRequest ;
50
51
import org .apache .paimon .rest .requests .RenameTableRequest ;
55
56
import org .apache .paimon .rest .responses .ErrorResponseResourceType ;
56
57
import org .apache .paimon .rest .responses .GetDatabaseResponse ;
57
58
import org .apache .paimon .rest .responses .GetTableResponse ;
59
+ import org .apache .paimon .rest .responses .GetViewResponse ;
58
60
import org .apache .paimon .rest .responses .ListDatabasesResponse ;
59
61
import org .apache .paimon .rest .responses .ListPartitionsResponse ;
60
62
import org .apache .paimon .rest .responses .ListTablesResponse ;
63
+ import org .apache .paimon .rest .responses .ListViewsResponse ;
61
64
import org .apache .paimon .schema .Schema ;
62
65
import org .apache .paimon .schema .SchemaChange ;
63
66
import org .apache .paimon .schema .TableSchema ;
64
67
import org .apache .paimon .table .FileStoreTable ;
65
68
import org .apache .paimon .table .Table ;
66
69
import org .apache .paimon .table .sink .BatchWriteBuilder ;
70
+ import org .apache .paimon .types .RowType ;
67
71
import org .apache .paimon .utils .Pair ;
72
+ import org .apache .paimon .view .View ;
73
+ import org .apache .paimon .view .ViewImpl ;
74
+ import org .apache .paimon .view .ViewSchema ;
68
75
69
76
import org .apache .paimon .shade .guava30 .com .google .common .collect .ImmutableList ;
70
77
@@ -290,8 +297,7 @@ public boolean commitSnapshot(Identifier identifier, Snapshot snapshot) {
290
297
CommitTableRequest request = new CommitTableRequest (identifier , snapshot );
291
298
CommitTableResponse response =
292
299
client .post (
293
- resourcePaths .commitTable (
294
- identifier .getDatabaseName (), identifier .getTableName ()),
300
+ resourcePaths .commitTable (identifier .getDatabaseName ()),
295
301
request ,
296
302
CommitTableResponse .class ,
297
303
headers ());
@@ -325,11 +331,7 @@ public void createTable(Identifier identifier, Schema schema, boolean ignoreIfEx
325
331
checkNotSystemTable (identifier , "createTable" );
326
332
validateAutoCreateClose (schema .options ());
327
333
CreateTableRequest request = new CreateTableRequest (identifier , schema );
328
- client .post (
329
- resourcePaths .tables (identifier .getDatabaseName ()),
330
- request ,
331
- GetTableResponse .class ,
332
- headers ());
334
+ client .post (resourcePaths .tables (identifier .getDatabaseName ()), request , headers ());
333
335
} catch (AlreadyExistsException e ) {
334
336
if (!ignoreIfExists ) {
335
337
throw new TableAlreadyExistException (identifier );
@@ -353,13 +355,8 @@ public void renameTable(Identifier fromTable, Identifier toTable, boolean ignore
353
355
checkNotSystemTable (fromTable , "renameTable" );
354
356
checkNotSystemTable (toTable , "renameTable" );
355
357
try {
356
- RenameTableRequest request = new RenameTableRequest (toTable );
357
- client .post (
358
- resourcePaths .renameTable (
359
- fromTable .getDatabaseName (), fromTable .getTableName ()),
360
- request ,
361
- GetTableResponse .class ,
362
- headers ());
358
+ RenameTableRequest request = new RenameTableRequest (fromTable , toTable );
359
+ client .post (resourcePaths .renameTable (fromTable .getDatabaseName ()), request , headers ());
363
360
} catch (NoSuchResourceException e ) {
364
361
if (!ignoreIfNotExists ) {
365
362
throw new TableNotExistException (fromTable );
@@ -381,7 +378,6 @@ public void alterTable(
381
378
client .post (
382
379
resourcePaths .table (identifier .getDatabaseName (), identifier .getTableName ()),
383
380
request ,
384
- GetTableResponse .class ,
385
381
headers ());
386
382
} catch (NoSuchResourceException e ) {
387
383
if (!ignoreIfNotExists ) {
@@ -532,6 +528,88 @@ public List<Partition> listPartitions(Identifier identifier) throws TableNotExis
532
528
return response .getPartitions ();
533
529
}
534
530
531
+ @ Override
532
+ public View getView (Identifier identifier ) throws ViewNotExistException {
533
+ try {
534
+ GetViewResponse response =
535
+ client .get (
536
+ resourcePaths .view (
537
+ identifier .getDatabaseName (), identifier .getTableName ()),
538
+ GetViewResponse .class ,
539
+ headers ());
540
+ return new ViewImpl (
541
+ identifier ,
542
+ response .getSchema ().rowType (),
543
+ response .getSchema ().query (),
544
+ response .getSchema ().comment (),
545
+ response .getSchema ().options ());
546
+ } catch (NoSuchResourceException e ) {
547
+ throw new ViewNotExistException (identifier );
548
+ }
549
+ }
550
+
551
+ @ Override
552
+ public void dropView (Identifier identifier , boolean ignoreIfNotExists )
553
+ throws ViewNotExistException {
554
+ try {
555
+ client .delete (
556
+ resourcePaths .view (identifier .getDatabaseName (), identifier .getTableName ()),
557
+ headers ());
558
+ } catch (NoSuchResourceException e ) {
559
+ if (!ignoreIfNotExists ) {
560
+ throw new ViewNotExistException (identifier );
561
+ }
562
+ }
563
+ }
564
+
565
+ @ Override
566
+ public void createView (Identifier identifier , View view , boolean ignoreIfExists )
567
+ throws ViewAlreadyExistException , DatabaseNotExistException {
568
+ try {
569
+ ViewSchema schema =
570
+ new ViewSchema (
571
+ new RowType (view .rowType ().getFields ()),
572
+ view .options (),
573
+ view .comment ().orElse (null ),
574
+ view .query ());
575
+ CreateViewRequest request = new CreateViewRequest (identifier , schema );
576
+ client .post (resourcePaths .views (identifier .getDatabaseName ()), request , headers ());
577
+ } catch (NoSuchResourceException e ) {
578
+ throw new DatabaseNotExistException (identifier .getDatabaseName ());
579
+ } catch (AlreadyExistsException e ) {
580
+ if (!ignoreIfExists ) {
581
+ throw new ViewAlreadyExistException (identifier );
582
+ }
583
+ }
584
+ }
585
+
586
+ @ Override
587
+ public List <String > listViews (String databaseName ) throws DatabaseNotExistException {
588
+ try {
589
+ ListViewsResponse response =
590
+ client .get (
591
+ resourcePaths .views (databaseName ), ListViewsResponse .class , headers ());
592
+ return response .getViews ();
593
+ } catch (NoSuchResourceException e ) {
594
+ throw new DatabaseNotExistException (databaseName );
595
+ }
596
+ }
597
+
598
+ @ Override
599
+ public void renameView (Identifier fromView , Identifier toView , boolean ignoreIfNotExists )
600
+ throws ViewNotExistException , ViewAlreadyExistException {
601
+ try {
602
+ RenameTableRequest request = new RenameTableRequest (fromView , toView );
603
+ client .post (resourcePaths .renameView (fromView .getDatabaseName ()), request , headers ());
604
+ } catch (NoSuchResourceException e ) {
605
+ if (!ignoreIfNotExists ) {
606
+ throw new ViewNotExistException (fromView );
607
+ }
608
+ } catch (AlreadyExistsException e ) {
609
+ throw new ViewAlreadyExistException (toView );
610
+ }
611
+ }
612
+
535
613
@ Override
536
614
public boolean caseSensitive () {
537
615
return options .getOptional (CASE_SENSITIVE ).orElse (true );
0 commit comments