use of com.google.firestore.admin.v1beta1.Index in project jaxdb by jaxdb.
the class DerbyDecompiler method getIndexes.
@Override
@SuppressWarnings("null")
Map<String, $Table.Indexes> getIndexes(final Connection connection) throws SQLException {
final Map<String, List<String>> tableNameToColumns = getTables(connection);
final PreparedStatement statement = connection.prepareStatement(indexSql);
final ResultSet rows = statement.executeQuery();
final Map<String, $Table.Indexes> tableNameToIndexes = new HashMap<>();
String lastTable = null;
$Table.Indexes indexes = null;
while (rows.next()) {
final String tableName = rows.getString(2);
final List<String> columnNames = tableNameToColumns.get(tableName);
if (!tableName.equals(lastTable)) {
lastTable = tableName;
tableNameToIndexes.put(tableName, indexes = new $Table.Indexes());
}
final String descriptor = rows.getString(3);
final boolean unique = descriptor.startsWith("UNIQUE");
final $IndexType.Enum type = descriptor.startsWith("HASH") ? $Index.Type$.HASH : $Index.Type$.BTREE;
final $Table.Indexes.Index index = new $Table.Indexes.Index();
indexes.addIndex(index);
if (!$Index.Type$.BTREE.equals(type))
index.setType$(new $Index.Type$(type));
if (unique)
index.setUnique$(new $Index.Unique$(unique));
final String[] columnNumbers = descriptor.substring(descriptor.lastIndexOf('(') + 1, descriptor.lastIndexOf(')')).split(",");
for (final String columnNumber : columnNumbers) {
final String columnName = columnNames.get(Integer.valueOf(columnNumber.trim()) - 1);
final $Table.Indexes.Index.Column column = new $Table.Indexes.Index.Column();
column.setName$(new $Table.Indexes.Index.Column.Name$(columnName.toLowerCase()));
index.addColumn(column);
}
}
return tableNameToIndexes;
}
use of com.google.firestore.admin.v1beta1.Index in project java-firestore by googleapis.
the class FirestoreAdminClientTest method getIndexTest2.
@Test
public void getIndexTest2() throws Exception {
Index expectedResponse = Index.newBuilder().setName(IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]").toString()).addAllFields(new ArrayList<Index.IndexField>()).build();
mockFirestoreAdmin.addResponse(expectedResponse);
String name = "name3373707";
Index actualResponse = client.getIndex(name);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockFirestoreAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetIndexRequest actualRequest = ((GetIndexRequest) actualRequests.get(0));
Assert.assertEquals(name, actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.firestore.admin.v1beta1.Index in project java-firestore by googleapis.
the class FirestoreAdminClientTest method getIndexTest.
@Test
public void getIndexTest() throws Exception {
Index expectedResponse = Index.newBuilder().setName(IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]").toString()).addAllFields(new ArrayList<Index.IndexField>()).build();
mockFirestoreAdmin.addResponse(expectedResponse);
IndexName name = IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]");
Index actualResponse = client.getIndex(name);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockFirestoreAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetIndexRequest actualRequest = ((GetIndexRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.firestore.admin.v1beta1.Index in project java-firestore by googleapis.
the class FirestoreAdminClientTest method createIndexTest.
@Test
public void createIndexTest() throws Exception {
Index expectedResponse = Index.newBuilder().setName(IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]").toString()).addAllFields(new ArrayList<Index.IndexField>()).build();
Operation resultOperation = Operation.newBuilder().setName("createIndexTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
mockFirestoreAdmin.addResponse(resultOperation);
CollectionGroupName parent = CollectionGroupName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]");
Index index = Index.newBuilder().build();
Index actualResponse = client.createIndexAsync(parent, index).get();
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockFirestoreAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateIndexRequest actualRequest = ((CreateIndexRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertEquals(index, actualRequest.getIndex());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.firestore.admin.v1beta1.Index in project s1tbx by senbox-org.
the class NetCDFUtils method createMapInfoX.
public static MapInfoX createMapInfoX(final Variable lonVar, final Variable latVar, final int sceneRasterWidth, final int sceneRasterHeight) throws IOException {
float pixelX;
float pixelY;
float easting;
float northing;
float pixelSizeX;
float pixelSizeY;
final NcAttributeMap lonAttrMap = NcAttributeMap.create(lonVar);
final Number lonValidMin = lonAttrMap.getNumericValue(NetcdfConstants.VALID_MIN_ATT_NAME);
final Number lonStep = lonAttrMap.getNumericValue(NetcdfConstants.STEP_ATT_NAME);
final NcAttributeMap latAttrMap = NcAttributeMap.create(latVar);
final Number latValidMin = latAttrMap.getNumericValue(NetcdfConstants.VALID_MIN_ATT_NAME);
final Number latStep = latAttrMap.getNumericValue(NetcdfConstants.STEP_ATT_NAME);
boolean yFlipped;
if (lonValidMin != null && lonStep != null && latValidMin != null && latStep != null) {
// COARDS convention uses 'valid_min' and 'step' attributes
pixelX = 0.5f;
pixelY = (sceneRasterHeight - 1.0f) + 0.5f;
easting = lonValidMin.floatValue();
northing = latValidMin.floatValue();
pixelSizeX = lonStep.floatValue();
pixelSizeY = latStep.floatValue();
// must flip
// todo - check
yFlipped = true;
} else {
// CF convention
final Array lonData = lonVar.read();
final Array latData = latVar.read();
final Index i0 = lonData.getIndex().set(0);
final Index i1 = lonData.getIndex().set(1);
pixelSizeX = lonData.getFloat(i1) - lonData.getFloat(i0);
easting = lonData.getFloat(i0);
final int latSize = (int) latVar.getSize();
final Index j0 = latData.getIndex().set(0);
final Index j1 = latData.getIndex().set(1);
pixelSizeY = latData.getFloat(j1) - latData.getFloat(j0);
pixelX = 0.5f;
pixelY = 0.5f;
// this should be the 'normal' case
if (pixelSizeY < 0) {
pixelSizeY *= -1;
yFlipped = false;
northing = latData.getFloat(latData.getIndex().set(0));
} else {
yFlipped = true;
northing = latData.getFloat(latData.getIndex().set(latSize - 1));
}
}
if (pixelSizeX <= 0 || pixelSizeY <= 0) {
return null;
}
final MapProjection projection = MapProjectionRegistry.getProjection(IdentityTransformDescriptor.NAME);
final MapInfo mapInfo = new MapInfo(projection, pixelX, pixelY, easting, northing, pixelSizeX, pixelSizeY, Datum.WGS_84);
mapInfo.setSceneWidth(sceneRasterWidth);
mapInfo.setSceneHeight(sceneRasterHeight);
return new MapInfoX(mapInfo, yFlipped);
}
Aggregations