private void doRegexTest() {
   AviaterRegexFilter filter3 =
       new AviaterRegexFilter(
           "otter2.otter_stability1|otter1.otter_stability1|"
               + RandomStringUtils.randomAlphabetic(200));
   boolean result = filter3.filter("otter1.otter_stability1");
   Assert.assertEquals(true, result);
   result = filter3.filter("otter2.otter_stability1");
   Assert.assertEquals(true, result);
 }
Example #2
0
  @Test
  public void testDisordered() {
    AviaterRegexFilter filter =
        new AviaterRegexFilter(
            "u\\..*,uvw\\..*,uv\\..*,a\\.x,a\\.xyz,a\\.xy,abc\\.x,abc\\.xyz,abc\\.xy,ab\\.x,ab\\.xyz,ab\\.xy");

    boolean result = filter.filter("u.abc");
    Assert.assertEquals(true, result);

    result = filter.filter("ab.x");
    Assert.assertEquals(true, result);

    result = filter.filter("ab.xyz1");
    Assert.assertEquals(false, result);

    result = filter.filter("abc.xyz");
    Assert.assertEquals(true, result);

    result = filter.filter("uv.xyz");
    Assert.assertEquals(true, result);
  }
Example #3
0
  private Entry parseRowsEvent(RowsLogEvent event) {
    try {
      TableMapLogEvent table = event.getTable();
      if (table == null) {
        // tableId对应的记录不存在
        throw new TableIdNotFoundException("not found tableId:" + event.getTableId());
      }

      String fullname = getSchemaNameAndTableName(table);
      if (nameFilter != null && !nameFilter.filter(fullname)) { // check name filter
        return null;
      }

      Header header =
          createHeader(binlogFileName, event.getHeader(), table.getDbName(), table.getTableName());
      RowChange.Builder rowChangeBuider = RowChange.newBuilder();
      rowChangeBuider.setTableId(event.getTableId());
      rowChangeBuider.setIsDdl(false);
      EventType eventType = null;
      int type = event.getHeader().getType();
      if (LogEvent.WRITE_ROWS_EVENT_V1 == type || LogEvent.WRITE_ROWS_EVENT == type) {
        eventType = EventType.INSERT;
      } else if (LogEvent.UPDATE_ROWS_EVENT_V1 == type || LogEvent.UPDATE_ROWS_EVENT == type) {
        eventType = EventType.UPDATE;
      } else if (LogEvent.DELETE_ROWS_EVENT_V1 == type || LogEvent.DELETE_ROWS_EVENT == type) {
        eventType = EventType.DELETE;
      } else {
        throw new CanalParseException("unsupport event type :" + event.getHeader().getType());
      }
      rowChangeBuider.setEventType(eventType);

      RowsLogBuffer buffer = event.getRowsBuf(charset.name());
      BitSet columns = event.getColumns();
      BitSet changeColumns = event.getColumns();
      TableMeta tableMeta = null;
      if (tableMetaCache != null) { // 入错存在table meta cache
        tableMeta = tableMetaCache.getTableMeta(fullname);
        if (tableMeta == null) {
          throw new CanalParseException("not found [" + fullname + "] in db , pls check!");
        }
      }

      while (buffer.nextOneRow(columns)) {
        // 处理row记录
        RowData.Builder rowDataBuilder = RowData.newBuilder();
        if (EventType.INSERT == eventType) {
          // insert的记录放在before字段中
          parseOneRow(rowDataBuilder, event, buffer, columns, true, tableMeta);
        } else if (EventType.DELETE == eventType) {
          // delete的记录放在before字段中
          parseOneRow(rowDataBuilder, event, buffer, columns, false, tableMeta);
        } else {
          // update需要处理before/after
          parseOneRow(rowDataBuilder, event, buffer, columns, false, tableMeta);
          if (!buffer.nextOneRow(changeColumns)) {
            rowChangeBuider.addRowDatas(rowDataBuilder.build());
            break;
          }

          parseOneRow(rowDataBuilder, event, buffer, event.getChangeColumns(), true, tableMeta);
        }

        rowChangeBuider.addRowDatas(rowDataBuilder.build());
      }
      return createEntry(header, EntryType.ROWDATA, rowChangeBuider.build().toByteString());
    } catch (Exception e) {
      throw new CanalParseException("parse row data failed.", e);
    }
  }
Example #4
0
  @Test
  public void test_regex() {
    AviaterRegexFilter filter = new AviaterRegexFilter("s1\\..*,s2\\..*");
    boolean result = filter.filter("s1.t1");
    Assert.assertEquals(true, result);

    result = filter.filter("s1.t2");
    Assert.assertEquals(true, result);

    result = filter.filter("");
    Assert.assertEquals(true, result);

    result = filter.filter("s12.t1");
    Assert.assertEquals(false, result);

    result = filter.filter("s2.t2");
    Assert.assertEquals(true, result);

    result = filter.filter("s3.t2");
    Assert.assertEquals(false, result);

    AviaterRegexFilter filter2 = new AviaterRegexFilter("s1\\..*,s2.t1");

    result = filter2.filter("s1.t1");
    Assert.assertEquals(true, result);

    result = filter2.filter("s1.t2");
    Assert.assertEquals(true, result);

    result = filter2.filter("s2.t1");
    Assert.assertEquals(true, result);

    AviaterRegexFilter filter3 = new AviaterRegexFilter("foooo,f.*t");

    result = filter3.filter("fooooot");
    Assert.assertEquals(true, result);

    AviaterRegexFilter filter4 =
        new AviaterRegexFilter(
            "otter2.otter_stability1|otter1.otter_stability1|retl.retl_mark|retl.retl_buffer|retl.xdual");
    result = filter4.filter("otter1.otter_stability1");
    Assert.assertEquals(true, result);
  }