|
@@ -1,72 +0,0 @@
|
|
|
-package demo.query.abtask;
|
|
|
-
|
|
|
-import db.Util;
|
|
|
-import util.Config;
|
|
|
-
|
|
|
-import java.sql.*;
|
|
|
-import java.util.logging.Logger;
|
|
|
-
|
|
|
-public class OtherAWithTwoStep {
|
|
|
- private static Logger logger = Logger.getLogger("OtherAWithTwoStep");
|
|
|
-// private static final String DATABASE_HOST = "192.168.3.42";
|
|
|
- private static String DATABASE_HOST = "192.168.50.181";
|
|
|
- private static int DATABASE_PORT = 8123;
|
|
|
-
|
|
|
-
|
|
|
- public static void main(String[] args) throws SQLException {
|
|
|
- Config.init();
|
|
|
- DATABASE_HOST = Config.getInstance().getDbHost();
|
|
|
-
|
|
|
- try {
|
|
|
- Class.forName("ru.yandex.clickhouse.ClickHouseDriver");
|
|
|
- Connection connection = DriverManager.getConnection(
|
|
|
- String.format("jdbc:clickhouse://%s:%d", DATABASE_HOST, DATABASE_PORT));
|
|
|
- Statement statement = connection.createStatement();
|
|
|
-
|
|
|
- long aid = Config.getInstance().getAid();
|
|
|
- ResultSet resultSet = statement.executeQuery(String.format("select begin, end from tasks.atask a where aid=%d", aid));
|
|
|
- ResultSetMetaData metaData = resultSet.getMetaData();
|
|
|
- int columnCount = metaData.getColumnCount();
|
|
|
-
|
|
|
- boolean hasAtaskResutl = false;
|
|
|
- long baseLineBegin = -1;
|
|
|
- long baseLineEnd = -1;
|
|
|
- while (resultSet.next()) {
|
|
|
- for (int i = 1; i <= columnCount; i++) {
|
|
|
- logger.info(metaData.getColumnName(i) + ":" + resultSet.getString(i));
|
|
|
- if(metaData.getColumnName(i).equals("begin")) {
|
|
|
- baseLineBegin = resultSet.getTimestamp(i).getTime();
|
|
|
- }
|
|
|
- else if(metaData.getColumnName(i).equals("end")) {
|
|
|
- baseLineEnd = resultSet.getTimestamp(i).getTime();
|
|
|
- }
|
|
|
- }
|
|
|
- hasAtaskResutl = true;
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- if(!hasAtaskResutl) {
|
|
|
- logger.severe("aid does not exist");
|
|
|
- return;
|
|
|
- }
|
|
|
- logger.info(String.format("queryResult: aid:%d begin:%d end:%d", aid, baseLineBegin, baseLineEnd));
|
|
|
-
|
|
|
-
|
|
|
- String sql = String.format("select aid from tasks.atask where end>=toDateTime('%s') and begin<=toDateTime('%s')",
|
|
|
- Util.uTCMilliSecondsToDateString(baseLineBegin), Util.uTCMilliSecondsToDateString(baseLineEnd));
|
|
|
- logger.info(String.format("sql:%s", sql));
|
|
|
- ResultSet resultSetOtherA = statement.executeQuery(sql);
|
|
|
- ResultSetMetaData metaDataOtherA = resultSetOtherA.getMetaData();
|
|
|
- while (resultSetOtherA.next()) {
|
|
|
- for (int i = 1; i <= metaDataOtherA.getColumnCount(); i++) {
|
|
|
- logger.info(" " + metaData.getColumnName(i) + ":" + resultSet.getString(i));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-}
|