Java Code Examples for org.apache.kafka.connect.data.Schema#BOOLEAN_SCHEMA

The following examples show how to use org.apache.kafka.connect.data.Schema#BOOLEAN_SCHEMA . 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: SerDeUtil.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 6 votes vote down vote up
private static Schema getKsqlSchemaForAvroSchema(org.apache.avro.Schema avroSchema) {
  switch (avroSchema.getType()) {
    case INT:
      return Schema.INT32_SCHEMA;
    case LONG:
      return Schema.INT64_SCHEMA;
    case DOUBLE:
    case FLOAT:
      return Schema.FLOAT64_SCHEMA;
    case BOOLEAN:
      return Schema.BOOLEAN_SCHEMA;
    case STRING:
      return Schema.STRING_SCHEMA;
    case ARRAY:
      return SchemaBuilder.array(getKsqlSchemaForAvroSchema(avroSchema.getElementType()));
    case MAP:
      return SchemaBuilder.map(Schema.STRING_SCHEMA,
                               getKsqlSchemaForAvroSchema(avroSchema.getValueType()));
    case UNION:
      return handleUnion(avroSchema);
      
    default:
      throw new KsqlException(String.format("KSQL doesn't currently support Avro type: %s",
                                            avroSchema.getFullName()));
  }
}
 
Example 2
Source File: SqlToJavaVisitor.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 6 votes vote down vote up
@Override
protected Pair<String, Schema> visitLogicalBinaryExpression(
    LogicalBinaryExpression node,
    Boolean unmangleNames
) {
  if (node.getType() == LogicalBinaryExpression.Type.OR) {
    return new Pair<>(
        formatBinaryExpression(" || ", node.getLeft(), node.getRight(), unmangleNames),
        Schema.BOOLEAN_SCHEMA
    );
  } else if (node.getType() == LogicalBinaryExpression.Type.AND) {
    return new Pair<>(
        formatBinaryExpression(" && ", node.getLeft(), node.getRight(), unmangleNames),
        Schema.BOOLEAN_SCHEMA
    );
  }
  throw new UnsupportedOperationException(
      format("not yet implemented: %s.visit%s", getClass().getName(),
             node.getClass().getSimpleName()
      )
  );
}
 
Example 3
Source File: SchemaUtil.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 6 votes vote down vote up
public static Schema getTypeSchema(final String sqlType) {
  switch (sqlType) {
    case "VARCHAR":
    case "STRING":
      return Schema.STRING_SCHEMA;
    case "BOOLEAN":
    case "BOOL":
      return Schema.BOOLEAN_SCHEMA;
    case "INTEGER":
    case "INT":
      return Schema.INT32_SCHEMA;
    case "BIGINT":
    case "LONG":
      return Schema.INT64_SCHEMA;
    case "DOUBLE":
      return Schema.FLOAT64_SCHEMA;
    default:
      return getKsqlComplexType(sqlType);
  }
}
 
Example 4
Source File: UnivocityFileReader.java    From kafka-connect-fs with Apache License 2.0 6 votes vote down vote up
private Schema strToSchema(String dataType) {
    switch (DataType.valueOf(dataType.trim().toUpperCase())) {
        case BYTE:
            return dataTypeMappingError && !allowNulls ? Schema.INT8_SCHEMA : Schema.OPTIONAL_INT8_SCHEMA;
        case SHORT:
            return dataTypeMappingError && !allowNulls ? Schema.INT16_SCHEMA : Schema.OPTIONAL_INT16_SCHEMA;
        case INT:
            return dataTypeMappingError && !allowNulls ? Schema.INT32_SCHEMA : Schema.OPTIONAL_INT32_SCHEMA;
        case LONG:
            return dataTypeMappingError && !allowNulls ? Schema.INT64_SCHEMA : Schema.OPTIONAL_INT64_SCHEMA;
        case FLOAT:
            return dataTypeMappingError && !allowNulls ? Schema.FLOAT32_SCHEMA : Schema.OPTIONAL_FLOAT32_SCHEMA;
        case DOUBLE:
            return dataTypeMappingError && !allowNulls ? Schema.FLOAT64_SCHEMA : Schema.OPTIONAL_FLOAT64_SCHEMA;
        case BOOLEAN:
            return dataTypeMappingError && !allowNulls ? Schema.BOOLEAN_SCHEMA : Schema.OPTIONAL_BOOLEAN_SCHEMA;
        case BYTES:
            return dataTypeMappingError && !allowNulls ? Schema.BYTES_SCHEMA : Schema.OPTIONAL_BYTES_SCHEMA;
        case STRING:
        default:
            return dataTypeMappingError && !allowNulls ? Schema.STRING_SCHEMA : Schema.OPTIONAL_STRING_SCHEMA;
    }
}
 
Example 5
Source File: SchemaTest.java    From schema-registry-transfer-smt with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonByteTypeSchemas() {
    Schema[] schemas = new Schema[]{
            // Boolean
            Schema.BOOLEAN_SCHEMA,
            Schema.OPTIONAL_BOOLEAN_SCHEMA,
            // Integers
            Schema.INT8_SCHEMA,
            Schema.INT16_SCHEMA,
            Schema.INT32_SCHEMA,
            Schema.INT64_SCHEMA,
            Schema.OPTIONAL_INT8_SCHEMA,
            Schema.OPTIONAL_INT16_SCHEMA,
            Schema.OPTIONAL_INT32_SCHEMA,
            Schema.OPTIONAL_INT64_SCHEMA,
            // Floats
            Schema.FLOAT32_SCHEMA,
            Schema.FLOAT64_SCHEMA,
            Schema.OPTIONAL_FLOAT32_SCHEMA,
            Schema.OPTIONAL_FLOAT64_SCHEMA,
            // String
            Schema.STRING_SCHEMA,
            Schema.OPTIONAL_STRING_SCHEMA,
            // Struct with a field of bytes
            SchemaBuilder.struct().name("record").
                    field("foo", Schema.BYTES_SCHEMA)
                    .build(),
            SchemaBuilder.struct().name("record").
                    field("foo", Schema.OPTIONAL_BYTES_SCHEMA)
                    .build(),
            // map<bytes, bytes>
            SchemaBuilder.map(Schema.BYTES_SCHEMA, Schema.OPTIONAL_BYTES_SCHEMA).build(),
            // array<bytes>
            SchemaBuilder.array(Schema.OPTIONAL_BYTES_SCHEMA).build()
    };

    for (Schema s : schemas) {
        assertFalse(ConnectSchemaUtil.isBytesSchema(s));
    }
}
 
Example 6
Source File: SqlToJavaVisitor.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 5 votes vote down vote up
@Override
protected Pair<String, Schema> visitBooleanLiteral(
    final BooleanLiteral node,
    final Boolean unmangleNames
) {
  return new Pair<>(String.valueOf(node.getValue()), Schema.BOOLEAN_SCHEMA);
}
 
Example 7
Source File: SqlToJavaVisitor.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 5 votes vote down vote up
@Override
protected Pair<String, Schema> visitComparisonExpression(
    ComparisonExpression node,
    Boolean unmangleNames
) {
  Pair<String, Schema> left = process(node.getLeft(), unmangleNames);
  Pair<String, Schema> right = process(node.getRight(), unmangleNames);

  String exprFormat = nullCheckPrefix(node.getType());
  switch (left.getRight().type()) {
    case STRING:
      exprFormat += visitStringComparisonExpression(node.getType());
      break;
    case MAP:
      throw new KsqlException("Cannot compare MAP values");
    case ARRAY:
      throw new KsqlException("Cannot compare ARRAY values");
    case BOOLEAN:
      exprFormat += visitBooleanComparisonExpression(node.getType());
      break;
    default:
      exprFormat += visitScalarComparisonExpression(node.getType());
      break;
  }
  String expr = "(" + String.format(exprFormat, left.getLeft(), right.getLeft()) + ")";
  return new Pair<>(expr, Schema.BOOLEAN_SCHEMA);
}
 
Example 8
Source File: SqlToJavaVisitor.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 5 votes vote down vote up
@Override
protected Pair<String, Schema> visitIsNullPredicate(
    IsNullPredicate node,
    Boolean unmangleNames
) {
  Pair<String, Schema> value = process(node.getValue(), unmangleNames);
  return new Pair<>("((" + value.getLeft() + ") == null )", Schema.BOOLEAN_SCHEMA);
}
 
Example 9
Source File: SqlToJavaVisitor.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 5 votes vote down vote up
@Override
protected Pair<String, Schema> visitIsNotNullPredicate(
    IsNotNullPredicate node,
    Boolean unmangleNames
) {
  Pair<String, Schema> value = process(node.getValue(), unmangleNames);
  return new Pair<>("((" + value.getLeft() + ") != null )", Schema.BOOLEAN_SCHEMA);
}
 
Example 10
Source File: BooleanFieldConverter.java    From mongo-kafka with Apache License 2.0 4 votes vote down vote up
public BooleanFieldConverter() {
  super(Schema.BOOLEAN_SCHEMA);
}
 
Example 11
Source File: SqlToJavaVisitor.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 4 votes vote down vote up
@Override
protected Pair<String, Schema> visitNotExpression(NotExpression node, Boolean unmangleNames) {
  String exprString = process(node.getValue(), unmangleNames).getLeft();
  return new Pair<>("(!" + exprString + ")", Schema.BOOLEAN_SCHEMA);
}
 
Example 12
Source File: SchemaUtilTest.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldGetTheCorrectJavaTypeForBoolean() {
  Schema schema = Schema.BOOLEAN_SCHEMA;
  Class javaClass = SchemaUtil.getJavaType(schema);
  assertThat(javaClass, equalTo(Boolean.class));
}
 
Example 13
Source File: BooleanFieldConverter.java    From kafka-connect-mongodb with Apache License 2.0 4 votes vote down vote up
public BooleanFieldConverter() {
    super(Schema.BOOLEAN_SCHEMA);
}