Пример #1
0
def test_promote_from_model_schema():
    m = _literal_models.Schema(
        "s3://some/place/",
        _type_models.SchemaType(
            [
                _type_models.SchemaType.SchemaColumn(
                    "a", _type_models.SchemaType.SchemaColumn.SchemaColumnType.BOOLEAN
                ),
                _type_models.SchemaType.SchemaColumn(
                    "b", _type_models.SchemaType.SchemaColumn.SchemaColumnType.DATETIME
                ),
                _type_models.SchemaType.SchemaColumn(
                    "c", _type_models.SchemaType.SchemaColumn.SchemaColumnType.DURATION
                ),
                _type_models.SchemaType.SchemaColumn("d", _type_models.SchemaType.SchemaColumn.SchemaColumnType.FLOAT),
                _type_models.SchemaType.SchemaColumn(
                    "e", _type_models.SchemaType.SchemaColumn.SchemaColumnType.INTEGER
                ),
                _type_models.SchemaType.SchemaColumn("f", _type_models.SchemaType.SchemaColumn.SchemaColumnType.STRING),
            ]
        ),
    )

    s = _schema_impl.Schema.promote_from_model(m)
    assert s.uri == "s3://some/place/"
    assert s.type.sdk_columns["a"].to_flyte_literal_type() == _primitives.Boolean.to_flyte_literal_type()
    assert s.type.sdk_columns["b"].to_flyte_literal_type() == _primitives.Datetime.to_flyte_literal_type()
    assert s.type.sdk_columns["c"].to_flyte_literal_type() == _primitives.Timedelta.to_flyte_literal_type()
    assert s.type.sdk_columns["d"].to_flyte_literal_type() == _primitives.Float.to_flyte_literal_type()
    assert s.type.sdk_columns["e"].to_flyte_literal_type() == _primitives.Integer.to_flyte_literal_type()
    assert s.type.sdk_columns["f"].to_flyte_literal_type() == _primitives.String.to_flyte_literal_type()
    assert s == m
Пример #2
0
def test_scalar_schema():
    schema_type = _types.SchemaType([
        _types.SchemaType.SchemaColumn("a", _types.SchemaType.SchemaColumn.SchemaColumnType.INTEGER),
        _types.SchemaType.SchemaColumn("b", _types.SchemaType.SchemaColumn.SchemaColumnType.FLOAT),
        _types.SchemaType.SchemaColumn("c", _types.SchemaType.SchemaColumn.SchemaColumnType.STRING),
        _types.SchemaType.SchemaColumn("d", _types.SchemaType.SchemaColumn.SchemaColumnType.DATETIME),
        _types.SchemaType.SchemaColumn("e", _types.SchemaType.SchemaColumn.SchemaColumnType.DURATION),
        _types.SchemaType.SchemaColumn("f", _types.SchemaType.SchemaColumn.SchemaColumnType.BOOLEAN)
    ])

    schema = literals.Schema(uri="asdf", type=schema_type)
    obj = literals.Scalar(schema=schema)
    assert obj.primitive is None
    assert obj.error is None
    assert obj.blob is None
    assert obj.binary is None
    assert obj.schema is not None
    assert obj.none_type is None
    assert obj.value.type.columns[0].name == 'a'
    assert len(obj.value.type.columns) == 6

    obj2 = literals.Scalar.from_flyte_idl(obj.to_flyte_idl())
    assert obj == obj2
    assert obj2.primitive is None
    assert obj2.error is None
    assert obj2.blob is None
    assert obj2.binary is None
    assert obj2.schema is not None
    assert obj2.none_type is None
    assert obj2.value.type.columns[0].name == 'a'
    assert len(obj2.value.type.columns) == 6
Пример #3
0
             "csv", _core_types.BlobType.BlobDimensionality.MULTIPART)),
     "s3://some/where/")),
  _blob_impl.MultiPartBlob("s3://some/where/", format="csv")),
 (literals.Scalar(blob=literals.Blob(
     literals.BlobMetadata(
         _core_types.BlobType(
             "", _core_types.BlobType.BlobDimensionality.MULTIPART)),
     "s3://some/where/")), _blob_impl.MultiPartBlob("s3://some/where/")),
 (literals.Scalar(schema=literals.Schema(
     "s3://some/where/",
     types.SchemaType([
         types.SchemaType.SchemaColumn(
             "a", types.SchemaType.SchemaColumn.SchemaColumnType.INTEGER),
         types.SchemaType.SchemaColumn(
             "b", types.SchemaType.SchemaColumn.SchemaColumnType.BOOLEAN),
         types.SchemaType.SchemaColumn(
             "c", types.SchemaType.SchemaColumn.SchemaColumnType.DATETIME),
         types.SchemaType.SchemaColumn(
             "d", types.SchemaType.SchemaColumn.SchemaColumnType.DURATION),
         types.SchemaType.SchemaColumn(
             "e", types.SchemaType.SchemaColumn.SchemaColumnType.FLOAT),
         types.SchemaType.SchemaColumn(
             "f", types.SchemaType.SchemaColumn.SchemaColumnType.STRING),
     ]))),
  _schema_impl.Schema(
      "s3://some/where/",
      _schema_impl.SchemaType.promote_from_model(
          types.SchemaType([
              types.SchemaType.SchemaColumn(
                  "a",
                  types.SchemaType.SchemaColumn.SchemaColumnType.INTEGER),
              types.SchemaType.SchemaColumn(