Java Code Examples for org.apache.kafka.common.utils.Time#milliseconds()

The following examples show how to use org.apache.kafka.common.utils.Time#milliseconds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MsSqlChange.java    From kafka-connect-cdc-mssql with Apache License 2.0 4 votes vote down vote up
public MsSqlChange build(TableMetadataProvider.TableMetadata tableMetadata, ResultSet resultSet, Time time) throws SQLException {
  MsSqlChange change = new MsSqlChange();
  change.timestamp = time.milliseconds();
  change.databaseName = tableMetadata.databaseName();
  change.schemaName = tableMetadata.schemaName();
  change.tableName = tableMetadata.tableName();

  final long sysChangeVersion = resultSet.getLong("__metadata_sys_change_version");
  final long sysChangeCreationVersion = resultSet.getLong("__metadata_sys_change_creation_version");
  final String changeOperation = resultSet.getString("__metadata_sys_change_operation");

  change.metadata = ImmutableMap.of(
      "sys_change_operation", changeOperation,
      "sys_change_creation_version", String.valueOf(sysChangeCreationVersion),
      "sys_change_version", String.valueOf(sysChangeVersion)
  );

  switch (changeOperation) {
    case "I":
      change.changeType = ChangeType.INSERT;
      break;
    case "U":
      change.changeType = ChangeType.UPDATE;
      break;
    case "D":
      change.changeType = ChangeType.DELETE;
      break;
    default:
      throw new UnsupportedOperationException(
          String.format("Unsupported sys_change_operation of '%s'", changeOperation)
      );
  }
  log.trace("build() - changeType = {}", change.changeType);

  change.keyColumns = new ArrayList<>(tableMetadata.keyColumns().size());
  change.valueColumns = new ArrayList<>(tableMetadata.columnSchemas().size());

  for (Map.Entry<String, Schema> kvp : tableMetadata.columnSchemas().entrySet()) {
    String columnName = kvp.getKey();
    Schema schema = kvp.getValue();
    Object value;
    if (Schema.Type.INT8 == schema.type()) {
      // Really lame Microsoft. A tiny int is stored as a single byte with a value of 0-255.
      // Explain how this should be returned as a short?
      value = resultSet.getByte(columnName);
    } else if (Schema.Type.INT32 == schema.type() &&
        Date.LOGICAL_NAME.equals(schema.name())) {
      value = new java.util.Date(
          resultSet.getDate(columnName, calendar).getTime()
      );
    } else if (Schema.Type.INT32 == schema.type() &&
        org.apache.kafka.connect.data.Time.LOGICAL_NAME.equals(schema.name())) {
      value = new java.util.Date(
          resultSet.getTime(columnName, calendar).getTime()
      );
    } else {
      value = resultSet.getObject(columnName);
    }

    log.trace("build() - columnName = '{}' value = '{}'", columnName, value);
    MsSqlColumnValue columnValue = new MsSqlColumnValue(columnName, schema, value);
    change.valueColumns.add(columnValue);
    if (tableMetadata.keyColumns().contains(columnName)) {
      change.keyColumns.add(columnValue);
    }
  }

  return change;
}
 
Example 2
Source File: TimeSerializationModule.java    From connect-utils with Apache License 2.0 4 votes vote down vote up
public Storage(Time time) {
  this.milliseconds = time.milliseconds();
  this.nanoseconds = time.nanoseconds();
  this.hiResClockMs = time.hiResClockMs();
}