Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions c/driver/postgresql/postgres_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ class PostgresType {
break;
}

// Don't add POSTGRESQL:type to top-level field (which is the schema)
if (type_id_ != PostgresTypeId::kRecord || !field_name_.empty()) {
NANOARROW_RETURN_NOT_OK(AddTypeMetadata(schema));
Comment thread
lidavidm marked this conversation as resolved.
}

NANOARROW_RETURN_NOT_OK(ArrowSchemaSetName(schema, field_name_.c_str()));
return NANOARROW_OK;
}
Expand All @@ -370,12 +375,25 @@ class PostgresType {
std::vector<PostgresType> children_;

static constexpr const char* kPostgresTypeKey = "ADBC:postgresql:typname";
static constexpr const char* kTypeKey = "POSTGRESQL:type";
static constexpr const char* kExtensionName = "ARROW:extension:name";
static constexpr const char* kOpaqueExtensionName = "arrow.opaque";
static constexpr const char* kJsonExtensionName = "arrow.json";
static constexpr const char* kUuidExtensionName = "arrow.uuid";
static constexpr const char* kExtensionMetadata = "ARROW:extension:metadata";

ArrowErrorCode AddTypeMetadata(ArrowSchema* schema) const {
const char* typname =
!typname_.empty() ? typname_.c_str() : PostgresTypname(type_id_);
nanoarrow::UniqueBuffer buffer;
NANOARROW_RETURN_NOT_OK(ArrowMetadataBuilderInit(buffer.get(), schema->metadata));
NANOARROW_RETURN_NOT_OK(ArrowMetadataBuilderAppend(
buffer.get(), ArrowCharView(kTypeKey), ArrowCharView(typname)));
NANOARROW_RETURN_NOT_OK(
ArrowSchemaSetMetadata(schema, reinterpret_cast<char*>(buffer->data)));
return NANOARROW_OK;
}

ArrowErrorCode AddPostgresTypeMetadata(ArrowSchema* schema,
const std::string& vendor_name) const {
// the typname_ may not always be set: an instance of this class can be
Expand Down
15 changes: 15 additions & 0 deletions c/driver/postgresql/postgres_type_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ TEST(PostgresTypeTest, PostgresTypeSetSchema) {
&typnameMetadataValue);
EXPECT_EQ(std::string(typnameMetadataValue.data, typnameMetadataValue.size_bytes),
"numeric");
typnameMetadataValue = ArrowCharView("<not found>");
ArrowMetadataGetValue(schema->metadata, ArrowCharView("POSTGRESQL:type"),
&typnameMetadataValue);
EXPECT_EQ(std::string(typnameMetadataValue.data, typnameMetadataValue.size_bytes),
"numeric");
ArrowMetadataGetValue(schema->metadata, ArrowCharView("ARROW:extension:name"),
&typnameMetadataValue);
EXPECT_EQ(std::string(typnameMetadataValue.data, typnameMetadataValue.size_bytes),
Expand All @@ -241,6 +246,11 @@ TEST(PostgresTypeTest, PostgresTypeSetSchema) {
ArrowCharView("ADBC:postgresql:typname"), &typnameMetadataValue);
EXPECT_EQ(std::string(typnameMetadataValue.data, typnameMetadataValue.size_bytes),
"numeric");
typnameMetadataValue = ArrowCharView("<not found>");
ArrowMetadataGetValue(schema->children[0]->metadata, ArrowCharView("POSTGRESQL:type"),
&typnameMetadataValue);
EXPECT_EQ(std::string(typnameMetadataValue.data, typnameMetadataValue.size_bytes),
"numeric");
schema.reset();

ArrowSchemaInit(schema.get());
Expand All @@ -267,6 +277,11 @@ TEST(PostgresTypeTest, PostgresTypeSetSchema) {
&typnameMetadataValue);
EXPECT_EQ(std::string(typnameMetadataValue.data, typnameMetadataValue.size_bytes),
"some_name");
typnameMetadataValue = ArrowCharView("<not found>");
ArrowMetadataGetValue(schema->metadata, ArrowCharView("POSTGRESQL:type"),
&typnameMetadataValue);
EXPECT_EQ(std::string(typnameMetadataValue.data, typnameMetadataValue.size_bytes),
"some_name");
schema.reset();
}

Expand Down
3 changes: 1 addition & 2 deletions c/driver/postgresql/result_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,8 @@ Status PqResultArrayReader::Initialize(int64_t* rows_affected) {
UNWRAP_ERRNO(Internal,
type_resolver_->FindWithDefault(helper_.FieldType(i), &child_type));

child_type = child_type.WithFieldName(helper_.FieldName(i));
UNWRAP_ERRNO(Internal, child_type.SetSchema(schema_->children[i], vendor_name_));
UNWRAP_ERRNO(Internal,
ArrowSchemaSetName(schema_->children[i], helper_.FieldName(i)));

std::unique_ptr<PostgresCopyFieldReader> child_reader;
UNWRAP_NANOARROW(
Expand Down

This file was deleted.

This file was deleted.

31 changes: 31 additions & 0 deletions c/driver/postgresql/validation/queries/type/bind/binary.txtcase
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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.

// part: metadata

[tags]
sql-type-name = "bytea"

// part: setup_query

CREATE TABLE test_binary (
res BYTEA
);

// part: bind_query

INSERT INTO test_binary (res) VALUES ($1)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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.

// part: metadata

[tags]
sql-type-name = "bytea"

// part: setup_query

CREATE TABLE test_binary_view (
res BYTEA
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.

// part: metadata

[tags]
sql-type-name = "bool"
21 changes: 21 additions & 0 deletions c/driver/postgresql/validation/queries/type/bind/date.txtcase
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.

// part: metadata

[tags]
sql-type-name = "date"
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
// specific language governing permissions and limitations
// under the License.

// part: metadata

[tags]
sql-type-name = "numeric"

// part: expected_schema
{
"format": "+s",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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.

// part: metadata

[tags]
sql-type-name = "bytea"

// part: setup_query

CREATE TABLE test_fixed_size_binary (
res BYTEA
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.

// part: metadata

[tags]
sql-type-name = "real"
field-type-name = "float4"
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.

// part: metadata

[tags]
sql-type-name = "real"
field-type-name = "float4"
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.

// part: metadata

[tags]
sql-type-name = "double precision"
field-type-name = "float8"
22 changes: 22 additions & 0 deletions c/driver/postgresql/validation/queries/type/bind/int16.txtcase
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.

// part: metadata

[tags]
sql-type-name = "smallint"
field-type-name = "int2"
22 changes: 22 additions & 0 deletions c/driver/postgresql/validation/queries/type/bind/int32.txtcase
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.

// part: metadata

[tags]
sql-type-name = "integer"
field-type-name = "int4"
22 changes: 22 additions & 0 deletions c/driver/postgresql/validation/queries/type/bind/int64.txtcase
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.

// part: metadata

[tags]
sql-type-name = "bigint"
field-type-name = "int8"

This file was deleted.

Loading
Loading