Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbeaver/dbeaver#23390 Support REAL_VECTOR type in HANA plugin #23391

Merged
merged 7 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/org.jkiss.dbeaver.ext.hana/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@

<datasource id="hana"/>

<type name="real_vector"/>
<type name="ST_Geometry"/>
<type name="ST_Point"/>
</provider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ public class HANAConstants {

// pseudo schema for PUBLIC SYNONYMs
public static final String SCHEMA_PUBLIC = "PUBLIC";

// Data type names
public static final String DATATYPENAME_REAL_VECTOR = "REAL_VECTOR";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static final String DATATYPENAME_REAL_VECTOR = "REAL_VECTOR";
public static final String DATA_TYPE_NAME_REAL_VECTOR = "REAL_VECTOR";

public static final String DATATYPENAME_ST_GEOMETRY = "ST_GEOMETRY";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static final String DATATYPENAME_ST_GEOMETRY = "ST_GEOMETRY";
public static final String DATA_TYPE_NAME_ST_GEOMETRY = "ST_GEOMETRY";

public static final String DATATYPENAME_ST_POINT = "ST_POINT";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static final String DATATYPENAME_ST_POINT = "ST_POINT";
public static final String DATA_TYPE_NAME_ST_POINT = "ST_POINT";

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.jkiss.dbeaver.ext.generic.model.GenericDataSource;
import org.jkiss.dbeaver.ext.generic.model.meta.GenericMetaModel;
import org.jkiss.dbeaver.ext.hana.model.plan.HANAPlanAnalyser;
import org.jkiss.dbeaver.model.DBPDataKind;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.DBPDataSourceInfo;
import org.jkiss.dbeaver.model.DBUtils;
Expand Down Expand Up @@ -72,6 +73,14 @@ protected DBPDataSourceInfo createDataSourceInfo(DBRProgressMonitor monitor, @No
return info;
}

@Override
public DBPDataKind resolveDataKind(String typeName, int valueType) {
if (HANAConstants.DATATYPENAME_REAL_VECTOR.equalsIgnoreCase(typeName)) {
return DBPDataKind.ARRAY;
}
return super.resolveDataKind(typeName, valueType);
}

/*
* search
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,14 @@ public String getDualTableName() {
public String getColumnTypeModifiers(@NotNull DBPDataSource dataSource, @NotNull DBSTypedObject column,
@NotNull String typeName, @NotNull DBPDataKind dataKind) {
String ucTypeName = CommonUtils.notEmpty(typeName).toUpperCase(Locale.ENGLISH);
if (("ST_POINT".equals(ucTypeName) || "ST_GEOMETRY".equals(ucTypeName))
if (HANAConstants.DATATYPENAME_REAL_VECTOR.equals(ucTypeName)) {
long dim = column.getMaxLength();
if ((dim > 0) && (dim <= 65000)) {
return "(" + Long.toString(dim) + ")";
}
return "";
} else if ((HANAConstants.DATATYPENAME_ST_POINT.equals(ucTypeName)
|| HANAConstants.DATATYPENAME_ST_GEOMETRY.equals(ucTypeName))
&& (column instanceof HANATableColumn)) {
HANATableColumn hanaColumn = (HANATableColumn) column;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.jkiss.dbeaver.ext.hana.model.data;

import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.ext.hana.model.HANAConstants;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.data.DBDFormatSettings;
import org.jkiss.dbeaver.model.data.DBDValueHandler;
Expand All @@ -33,8 +34,10 @@ public class HANAValueHandlerProvider implements DBDValueHandlerProvider {
public DBDValueHandler getValueHandler(DBPDataSource dataSource, DBDFormatSettings preferences,
DBSTypedObject typedObject) {
switch (typedObject.getTypeName()) {
case "ST_GEOMETRY":
case "ST_POINT":
case HANAConstants.DATATYPENAME_REAL_VECTOR:
return HANAVectorValueHandler.INSTANCE;
case HANAConstants.DATATYPENAME_ST_GEOMETRY:
case HANAConstants.DATATYPENAME_ST_POINT:
return HANAGeometryValueHandler.INSTANCE;
default:
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* Licensed 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.jkiss.dbeaver.ext.hana.model.data;

import java.sql.SQLException;
import java.sql.Types;

import org.jkiss.dbeaver.model.data.DBDCollection;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.DBCLogicalOperator;
import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCollection;
import org.jkiss.dbeaver.model.impl.jdbc.data.handlers.JDBCArrayValueHandler;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;

public class HANAVectorValueHandler extends JDBCArrayValueHandler {

public static final HANAVectorValueHandler INSTANCE = new HANAVectorValueHandler();

private static DBCLogicalOperator[] SUPPORTED_OPERATORS = { DBCLogicalOperator.IS_NOT_NULL,
DBCLogicalOperator.IS_NULL };

@Override
protected boolean useGetArray(DBCSession session, DBSTypedObject type) {
return true;
}

@Override
protected void bindParameter(JDBCSession session, JDBCPreparedStatement statement, DBSTypedObject paramType,
int paramIndex, Object value) throws DBCException, SQLException {
if (value == null) {
statement.setNull(paramIndex, Types.ARRAY);
} else if (value instanceof DBDCollection) {
DBDCollection collection = (DBDCollection) value;
if (collection.isNull()) {
statement.setNull(paramIndex, Types.ARRAY);
} else if (collection instanceof JDBCCollection) {
JDBCCollection jc = (JDBCCollection) collection;
if (jc.getComponentType().getTypeID() != Types.REAL) {
throw new DBCException("Only REAL numbers are allowed in vectors");
}
float[] nvals = new float[jc.size()];
for (int i = 0; i < nvals.length; ++i) {
Float val = (Float) jc.get(i);
if (val == null) {
throw new DBCException("NULL elements are not allowed in vectors");
}
nvals[i] = val;
}
statement.setObject(paramIndex, nvals);
} else {
throw new DBCException("Array parameter type '" + value.getClass().getName() + "' not supported");
}
} else {
throw new DBCException("Array parameter type '" + value.getClass().getName() + "' not supported");
}
}

@Override
public DBCLogicalOperator[] getSupportedOperators(DBSTypedObject attribute) {
return SUPPORTED_OPERATORS;
}
}