无法使用azure存储java库中的筛选器

nue99wik  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(245)

我一直在尝试将azurecosmosdb与spring启动应用程序集成。cosmosdb使用表api并存储一个entity:database entity 属性
我正在使用azure存储库连接到数据库。我可以从数据库中检索数据,但过滤器不能正常工作。我可以按rowkey和partitionkey进行过滤,但是不能过滤sensorvalue和timestamp。应用这些筛选器时,数据库不返回任何实体。这是我用来测试过滤器的代码:

TableClientProvider provider = new TableClientProvider();
CloudTableClient tableClient = provider.getTableClientReference();
String tableName = "NodeSensorsTable";
CloudTable cloudTable = tableClient.getTableReference(tableName);
cloudTable.createIfNotExists();
String dateString ="25/11/2020 13:04:28";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Date date = simpleDateFormat.parse(dateString);
String filter = TableQuery.generateFilterCondition("Timestamp", TableQuery.QueryComparisons.LESS_THAN_OR_EQUAL, date);
TableQuery<SproutEntity> query = TableQuery.from(SproutEntity.class).where(filter);
for(SproutEntity entity : cloudTable.execute(query)) {
  SproutDataDTO dataDTO = new SproutDataDTO(entity);
  System.out.println(dataDTO.getValue());
}

我用来获取数据的实体可以很好地插入和检索数据。我也尝试过在azure Jmeter 板中使用从dataexplorer生成的过滤器字符串,但效果相同。此方法中使用的唯一库是azure存储库。这是我的spring boot应用程序中的pom.xml:
4.0.0 org.springframework.boot spring boot starter parent 2.3.4.release com.spreat api 0.0.1-snapshot api spreat api for iot insights

<properties>
    <java.version>14</java.version>
    <azure.version>2.2.0</azure.version>
</properties>

<dependencies>
    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-storage</artifactId>
        <version>8.6.5</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-hateoas</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.4.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.4.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.12.0-rc1</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.12.0-rc1</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.12.0-rc1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <version>3.6.0</version>
        <scope>test</scope>
    </dependency>
    <!--<dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-cosmosdb-spring-boot-starter</artifactId>
        <version>2.3.3</version>
    </dependency> -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.5</version>
            <executions>
                <execution>
                        <id>default-prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>default-report</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.sonarsource.scanner.maven</groupId>
            <artifactId>sonar-maven-plugin</artifactId>
            <version>3.7.0.1746</version>
        </plugin>
    </plugins>
</build>

以前有人遇到过这个问题吗?如果是,你的解决方案是什么?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题