Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ private static void createTimeSeries() {
+ "datatype=double, "
+ "encoding=plain, "
+ "compression=uncompressed");
statement.addBatch(
"create timeseries root.vehicle.d3.s1 with "
+ "datatype=int32, "
+ "encoding=plain, "
+ "compression=uncompressed");
statement.executeBatch();
} catch (SQLException throwable) {
fail(throwable.getMessage());
Expand Down Expand Up @@ -168,6 +173,16 @@ private static void generateData() {
String.format(
"insert into root.vehicle.d2(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
900, 4, 4, 4, 4));
// Toy series for cluster UDF (l=3, k=2): windows [1,2,3], [10,20,30], [1,5,1]. With
// norm=false,
// k-means groups the first two windows; k-shape / medoidshape group windows 0 and 2
// (shape-related).
int[] toy = {1, 2, 3, 10, 20, 30, 1, 5, 1};
for (int i = 0; i < toy.length; i++) {
statement.addBatch(
String.format(
"insert into root.vehicle.d3(timestamp,s1) values(%d,%d)", (i + 1) * 100, toy[i]));
}
statement.executeBatch();
} catch (SQLException throwable) {
fail(throwable.getMessage());
Expand All @@ -179,6 +194,7 @@ private static void registerUDF() {
Statement statement = connection.createStatement()) {
statement.execute("create function iqr as 'org.apache.iotdb.library.anomaly.UDTFIQR'");
statement.execute("create function ar as 'org.apache.iotdb.library.dlearn.UDTFAR'");
statement.execute("create function cluster as 'org.apache.iotdb.library.dlearn.UDTFCluster'");
} catch (SQLException throwable) {
fail(throwable.getMessage());
}
Expand Down Expand Up @@ -308,4 +324,70 @@ public void testAR4() {
fail(throwable.getMessage());
}
}

@Test
public void testCluster1() {
String sqlStr =
"select cluster(d3.s1, 'l'='3', 'k'='2', 'method'='kmeans', 'norm'='false', "
+ "'maxiter'='50', 'output'='label') from root.vehicle";
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(sqlStr)) {
resultSet.next();
int l0 = resultSet.getInt(2);
resultSet.next();
int l1 = resultSet.getInt(2);
resultSet.next();
int l2 = resultSet.getInt(2);
Assert.assertFalse(resultSet.next());
Assert.assertEquals(l0, l2);
Assert.assertNotEquals(l0, l1);
} catch (SQLException throwable) {
fail(throwable.getMessage());
}
}

@Test
public void testCluster2() {
String sqlStr =
"select cluster(d3.s1, 'l'='3', 'k'='2', 'method'='kshape', 'norm'='true', "
+ "'maxiter'='50', 'output'='label') from root.vehicle";
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(sqlStr)) {
resultSet.next();
int l0 = resultSet.getInt(2);
resultSet.next();
int l1 = resultSet.getInt(2);
resultSet.next();
int l2 = resultSet.getInt(2);
Assert.assertFalse(resultSet.next());
Assert.assertEquals(l0, l1);
Assert.assertNotEquals(l0, l2);
} catch (SQLException throwable) {
fail(throwable.getMessage());
}
}

@Test
public void testCluster3() {
String sqlStr =
"select cluster(d3.s1, 'l'='3', 'k'='2', 'method'='medoidshape', 'norm'='true', "
+ "'sample_rate'='1', 'maxiter'='50', 'output'='label') from root.vehicle";
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(sqlStr)) {
resultSet.next();
int l0 = resultSet.getInt(2);
resultSet.next();
int l1 = resultSet.getInt(2);
resultSet.next();
int l2 = resultSet.getInt(2);
Assert.assertFalse(resultSet.next());
Assert.assertEquals(l0, l1);
Assert.assertNotEquals(l0, l2);
} catch (SQLException throwable) {
fail(throwable.getMessage());
}
}
}
6 changes: 4 additions & 2 deletions library-udf/pom.xml
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the version of dev/1.3 should be 1.3.x?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Have restored the pom file.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-parent</artifactId>
<version>1.3.7-SNAPSHOT</version>
<version>2.0.7-SNAPSHOT</version>
</parent>
<artifactId>library-udf</artifactId>
<name>IoTDB: UDF</name>
Expand All @@ -41,7 +41,7 @@
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>udf-api</artifactId>
<version>1.3.7-SNAPSHOT</version>
<version>2.0.7-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand All @@ -58,10 +58,12 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>${commons-math3.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<!-- FFT, IFFT, LowPass, HighPass -->
<dependency>
Expand Down
Loading