Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,8 @@
// specific language governing permissions and limitations
// under the License.

// part: expected_schema
// part: setup_query

{
"format": "+s",
"children": [
{
"name": "res",
"format": "l",
"flags": ["nullable"]
}
]
}
CREATE TABLE test_int32 (
res INT4
);
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@
// specific language governing permissions and limitations
// under the License.

// part: expected_schema
// part: query

{
"format": "+s",
"children": [
{
"name": "res",
"format": "l",
"flags": ["nullable"]
}
]
}
SELECT CAST(131072 AS INT4) AS res
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
// specific language governing permissions and limitations
// under the License.

// part: expected_schema
// part: setup_query

{
"format": "+s",
"children": [
{
"name": "res",
"format": "l",
"flags": ["nullable"]
}
]
}
CREATE TABLE test_int32 (
idx INTEGER,
res INT4
);

INSERT INTO test_int32 (idx, res) VALUES (1, 131072);
INSERT INTO test_int32 (idx, res) VALUES (2, 2147483647);
INSERT INTO test_int32 (idx, res) VALUES (3, -2147483648);
INSERT INTO test_int32 (idx, res) VALUES (4, 0);
INSERT INTO test_int32 (idx, res) VALUES (5, NULL);
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]
field-type-name = "jsonb"
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]
field-type-name = "varchar"
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]
field-type-name = "varchar"
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]
field-type-name = "varchar"
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

[tags]
sql-type-name = "TIMESTAMP"
field-type-name = "timestamp"

// part: setup_query

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

[tags]
sql-type-name = "TIMESTAMP"
field-type-name = "timestamp"

// part: setup_query

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

[tags]
sql-type-name = "TIMESTAMP"
field-type-name = "timestamp"

// part: setup_query

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

[tags]
sql-type-name = "TIMESTAMP"
field-type-name = "timestamp"

// part: setup_query

Expand Down
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]
field-type-name = "varchar"
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]
field-type-name = "varchar"
21 changes: 21 additions & 0 deletions c/driver/postgresql/validation/queries/ingest/binary.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]
field-type-name = "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]
field-type-name = "bytea"
21 changes: 21 additions & 0 deletions c/driver/postgresql/validation/queries/ingest/boolean.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]
field-type-name = "bool"
Loading
Loading