Skip to content

Commit

Permalink
(Partially) revert "ogr2ogr: preserve OFSTJSON when using ArrowArray …
Browse files Browse the repository at this point in the history
…code path"

This partially reverts commit fb92aa5.

No longer needed since previous commit
  • Loading branch information
rouault committed Oct 29, 2023
1 parent a9879cb commit 6eeffa5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 49 deletions.
36 changes: 3 additions & 33 deletions apps/ogr2ogr_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3886,49 +3886,19 @@ bool SetupTargetLayer::CanUseWriteArrowBatch(
poDstFDefn->GetGeomFieldCount() ==
poSrcFDefn->GetGeomFieldCount())
{
std::map<std::string, OGRFieldSubType>
oMapFieldNameToSubType;
for (int i = 0; i < poSrcFDefn->GetFieldCount(); ++i)
{
const auto poSrcFieldDefn =
poSrcFDefn->GetFieldDefn(i);
if (poSrcFieldDefn->GetSubType() == OFSTJSON)
oMapFieldNameToSubType[poSrcFieldDefn
->GetNameRef()] =
poSrcFieldDefn->GetSubType();
}
std::set<std::string> oSetGeomFieldNames;
for (int i = 0; i < poSrcFDefn->GetGeomFieldCount();
++i)
{
const auto poSrcGeomFieldDefn =
poSrcFDefn->GetGeomFieldDefn(i);
oSetGeomFieldNames.insert(
poSrcGeomFieldDefn->GetNameRef());
}

// Create output fields using CreateFieldFromArrowSchema()
for (int i = 0; i < schemaSrc.n_children; ++i)
{
const char *pszFieldName =
schemaSrc.children[i]->name;
CPLStringList aosOptions;
auto oIterSubType =
oMapFieldNameToSubType.find(pszFieldName);
if (oIterSubType != oMapFieldNameToSubType.end())
{
aosOptions.SetNameValue(
"SUBTYPE", OGR_GetFieldSubTypeName(
oIterSubType->second));
}
if (!EQUAL(pszFieldName, "OGC_FID") &&
!EQUAL(pszFieldName, "wkb_geometry") &&
!EQUAL(pszFieldName,
poSrcLayer->GetFIDColumn()) &&
oSetGeomFieldNames.find(pszFieldName) ==
oSetGeomFieldNames.end() &&
poSrcFDefn->GetGeomFieldIndex(pszFieldName) <
0 &&
!poDstLayer->CreateFieldFromArrowSchema(
schemaSrc.children[i], aosOptions.List()))
schemaSrc.children[i], nullptr))
{
CPLError(CE_Failure, CPLE_AppDefined,
"Cannot create field %s",
Expand Down
19 changes: 3 additions & 16 deletions ogr/ogrsf_frmts/generic/ogrlayerarrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5329,14 +5329,7 @@ bool OGRLayer::CreateFieldFromArrowSchemaInternal(
{
if (strcmp(format, sType.arrowType) == 0)
{
OGRFieldSubType eSubType = sType.eSubType;
if (sType.eType == OFTString &&
EQUAL(CSLFetchNameValueDef(papszOptions, "SUBTYPE", ""),
"JSON"))
{
eSubType = OFSTJSON;
}
return AddField(sType.eType, eSubType, 0, 0);
return AddField(sType.eType, sType.eSubType, 0, 0);
}
}

Expand Down Expand Up @@ -5467,13 +5460,10 @@ bool OGRLayer::CreateFieldFromArrowSchemaInternal(
*
* This method and CreateField() are mutually exclusive in the same session.
*
* The base implementation of CreateFieldFromArrowSchema() supports the
* option SUBTYPE=JSON for fields of type string.
*
* This method is the same as the C function OGR_L_CreateFieldFromArrowSchema().
*
* @param schema Schema of the field to create.
* @param papszOptions Options. Null terminated list, or nullptr.
* @param papszOptions Options (none currently). Null terminated list, or nullptr.
* @return true in case of success
* @since 3.8
*/
Expand Down Expand Up @@ -5513,14 +5503,11 @@ bool OGRLayer::CreateFieldFromArrowSchema(const struct ArrowSchema *schema,
*
* This method and CreateField() are mutually exclusive in the same session.
*
* The base implementation of CreateFieldFromArrowSchema() supports the
* option SUBTYPE=JSON for fields of type string.
*
* This method is the same as the C++ method OGRLayer::CreateFieldFromArrowSchema().
*
* @param hLayer Layer.
* @param schema Schema of the field to create.
* @param papszOptions Options. Null terminated list, or nullptr.
* @param papszOptions Options (none currently). Null terminated list, or nullptr.
* @return true in case of success
* @since 3.8
*/
Expand Down

0 comments on commit 6eeffa5

Please sign in to comment.