Search in sources :

Example 41 with Index

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;
}
Also used : HashMap(java.util.HashMap) PreparedStatement(java.sql.PreparedStatement) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Index(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Index) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$IndexType(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$IndexType) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List)

Example 42 with Index

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) GetIndexRequest(com.google.firestore.admin.v1.GetIndexRequest) Index(com.google.firestore.admin.v1.Index) Test(org.junit.Test)

Example 43 with Index

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()));
}
Also used : IndexName(com.google.firestore.admin.v1.IndexName) AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) GetIndexRequest(com.google.firestore.admin.v1.GetIndexRequest) Index(com.google.firestore.admin.v1.Index) Test(org.junit.Test)

Example 44 with Index

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) Index(com.google.firestore.admin.v1.Index) Operation(com.google.longrunning.Operation) CollectionGroupName(com.google.firestore.admin.v1.CollectionGroupName) CreateIndexRequest(com.google.firestore.admin.v1.CreateIndexRequest) Test(org.junit.Test)

Example 45 with Index

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);
}
Also used : Array(ucar.ma2.Array) MapProjection(org.esa.snap.core.dataop.maptransf.MapProjection) MapInfo(org.esa.snap.core.dataop.maptransf.MapInfo) Index(ucar.ma2.Index)

Aggregations

Index (ucar.ma2.Index)30 Array (ucar.ma2.Array)20 ArrayList (java.util.ArrayList)17 Test (org.junit.Test)12 Attribute (ucar.nc2.Attribute)11 AbstractMessage (com.google.protobuf.AbstractMessage)10 WritableRaster (java.awt.image.WritableRaster)10 IOException (java.io.IOException)10 ArrayFloat (ucar.ma2.ArrayFloat)10 Index (com.google.firestore.admin.v1.Index)9 Dimension (ucar.nc2.Dimension)9 NetcdfFileWriteable (ucar.nc2.NetcdfFileWriteable)8 Variable (ucar.nc2.Variable)8 ArrayDouble (ucar.ma2.ArrayDouble)7 NetcdfFile (ucar.nc2.NetcdfFile)7 Index (com.google.datastore.admin.v1.Index)4 FirestoreAdminBlockingStub (com.google.firestore.admin.v1beta1.FirestoreAdminGrpc.FirestoreAdminBlockingStub)4 Operation (com.google.longrunning.Operation)4 SampleModel (java.awt.image.SampleModel)4 File (java.io.File)4