Skip to content

Commit

Permalink
support get view
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry-024 committed Jan 14, 2025
1 parent 5de4d95 commit 9dcfb77
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 0 deletions.
46 changes: 46 additions & 0 deletions paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.apache.paimon.rest.responses.ErrorResponseResourceType;
import org.apache.paimon.rest.responses.GetDatabaseResponse;
import org.apache.paimon.rest.responses.GetTableResponse;
import org.apache.paimon.rest.responses.GetViewResponse;
import org.apache.paimon.rest.responses.ListDatabasesResponse;
import org.apache.paimon.rest.responses.ListPartitionsResponse;
import org.apache.paimon.rest.responses.ListTablesResponse;
Expand All @@ -68,6 +69,8 @@
import org.apache.paimon.table.sink.BatchWriteBuilder;
import org.apache.paimon.utils.Pair;
import org.apache.paimon.utils.Preconditions;
import org.apache.paimon.view.View;
import org.apache.paimon.view.ViewImpl;

import org.apache.paimon.shade.guava30.com.google.common.collect.ImmutableList;

Expand Down Expand Up @@ -505,6 +508,49 @@ public List<Partition> listPartitions(Identifier identifier) throws TableNotExis
return response.getPartitions();
}

@Override
public View getView(Identifier identifier) throws ViewNotExistException {
try {
GetViewResponse response =
client.get(
resourcePaths.view(
identifier.getDatabaseName(), identifier.getTableName()),
GetViewResponse.class,
headers());
return new ViewImpl(
identifier,
response.getSchema().rowType(),
response.getSchema().query(),
response.getSchema().comment(),
response.getSchema().options());
} catch (NoSuchResourceException e) {
throw new ViewNotExistException(identifier);
}
}

@Override
public void dropView(Identifier identifier, boolean ignoreIfNotExists)
throws ViewNotExistException {
throw new UnsupportedOperationException();
}

@Override
public void createView(Identifier identifier, View view, boolean ignoreIfExists)
throws ViewAlreadyExistException, DatabaseNotExistException {
throw new UnsupportedOperationException();
}

@Override
public List<String> listViews(String databaseName) throws DatabaseNotExistException {
throw new UnsupportedOperationException();
}

@Override
public void renameView(Identifier fromView, Identifier toView, boolean ignoreIfNotExists)
throws ViewNotExistException, ViewAlreadyExistException {
throw new UnsupportedOperationException();
}

@Override
public boolean caseSensitive() {
return options.getOptional(CASE_SENSITIVE).orElse(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,8 @@ public String markDonePartitions(String databaseName, String tableName) {
return SLASH.join(
V1, prefix, DATABASES, databaseName, TABLES, tableName, "partitions", "mark");
}

public String view(String databaseName, String viewName) {
return SLASH.join(V1, prefix, DATABASES, databaseName, "views", viewName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.paimon.rest.responses;

import org.apache.paimon.rest.RESTResponse;

import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonGetter;
import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonProperty;

/** Response for getting view. */
@JsonIgnoreProperties(ignoreUnknown = true)
public class GetViewResponse implements RESTResponse {

private static final String FIELD_ID = "id";
private static final String FIELD_NAME = "name";
private static final String FIELD_SCHEMA = "schema";

@JsonProperty(FIELD_ID)
private final String id;

@JsonProperty(FIELD_NAME)
private final String name;

@JsonProperty(FIELD_SCHEMA)
private final ViewSchema schema;

@JsonCreator
public GetViewResponse(
@JsonProperty(FIELD_ID) String id,
@JsonProperty(FIELD_NAME) String name,
@JsonProperty(FIELD_SCHEMA) ViewSchema schema) {
this.id = id;
this.name = name;
this.schema = schema;
}

@JsonGetter(FIELD_ID)
public String getId() {
return this.id;
}

@JsonGetter(FIELD_NAME)
public String getName() {
return this.name;
}

@JsonGetter(FIELD_SCHEMA)
public ViewSchema getSchema() {
return this.schema;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.paimon.rest.responses;

import org.apache.paimon.types.DataField;
import org.apache.paimon.types.RowType;

import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonGetter;
import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonInclude;
import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonProperty;

import javax.annotation.Nullable;

import java.util.List;
import java.util.Map;

public class ViewSchema {
private static final String FIELD_FIELDS = "fields";
private static final String FIELD_OPTIONS = "options";
private static final String FIELD_COMMENT = "comment";
private static final String FIELD_QUERY = "query";

@JsonProperty(FIELD_QUERY)
private final String query;

@Nullable
@JsonProperty(FIELD_COMMENT)
@JsonInclude(JsonInclude.Include.NON_NULL)
private final String comment;

@JsonProperty(FIELD_OPTIONS)
private final Map<String, String> options;

@JsonProperty(FIELD_FIELDS)
private final List<DataField> fields;

@JsonCreator
public ViewSchema(
@JsonProperty(FIELD_FIELDS) List<DataField> fields,
@JsonProperty(FIELD_OPTIONS) Map<String, String> options,
@Nullable @JsonProperty(FIELD_COMMENT) String comment,
@JsonProperty(FIELD_QUERY) String query) {
this.fields = fields;
this.options = options;
this.comment = comment;
this.query = query;
}

public RowType rowType() {
return new RowType(fields);
}

@JsonGetter(FIELD_QUERY)
public String query() {
return query;
}

@Nullable
@JsonGetter(FIELD_COMMENT)
public String comment() {
return comment;
}

@JsonGetter(FIELD_OPTIONS)
public Map<String, String> options() {
return options;
}

@JsonGetter(FIELD_FIELDS)
public List<DataField> fields() {
return fields;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.apache.paimon.catalog.Identifier;
import org.apache.paimon.types.RowType;

import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import javax.annotation.Nullable;

import java.util.HashMap;
Expand All @@ -29,6 +31,7 @@
import java.util.Optional;

/** Implementation of {@link View}. */
@JsonIgnoreProperties(ignoreUnknown = true)
public class ViewImpl implements View {

private final Identifier identifier;
Expand Down

0 comments on commit 9dcfb77

Please sign in to comment.