DataFile Serialization for REST Scan Planning
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 30/100
Direção de pesquisa
Comece lendo a implementação atual de DataFile, Record, DataFile.from_args() e StructProtocol e, em seguida, compare o esquema REST com ContentFileParser.java e o protótipo em rest/models.py. A issue só estará concluída quando um design de desserialização acordado tratar partições, mapas, limites e conversões de conteúdo sem quebrar a compatibilidade com Avro.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Related to #2775
In order to support, scan planning for the REST catalog. The API returns file scan tasks as JSON, and I need to deserialize them into DataFile and DeleteFile objects. The API returns JSON like this:
{
"plan-status": "completed",
"delete-files": [
{
"spec-id": 0,
"content": "position-deletes",
"file-path": "s3://bucket/deletes.parquet",
"file-format": "parquet",
"partition": ["test"],
"file-size-in-bytes": 1529,
"record-count": 1,
"column-sizes": {"keys": [2147483546], "values": [134]},
"lower-bounds": {"keys": [2147483546], "values": ["73333A2F..."]},
...
}
],
"file-scan-tasks": [
{
"data-file": {
"spec-id": 0,
"content": "data",
"file-path": "s3://bucket/data.parquet",
...
},
"delete-file-references": [0],
"residual-filter": true
}
]
}
The format is defined in the https://github.com/apache/iceberg/blob/main/open-api/rest-catalog-open-api.yaml#L4337-L4389, and Java parses it via ContentFileParser.java.
Issue
The REST API representation differs from our internal representation:
- Partition is unbound
["test"]instead of a Record - Maps are
{"keys": [...], "values": [...]}instead of{key: value} - Bounds are primitives (bytes, hex)
- content is
position-deletesstring instead of enum int
The current state of our python DataFile:
- Extends
Record(for Avro compatibility) - Uses positional array access (
_data[pos]) - Constructed via
DataFile.from_args()factory - Tightly coupled to Avro reader/writer via
StructProtocol
Our DataFile isn't Pydantic, so we can't just do DataFile.model_validate(json) with validators to handle these conversions. Also, DataFile handles both data files and delete files via the content field. So it's really a content file.
Options
1. Translation layer (RestContentFile)
Create a separate Pydantic model that parses JSON with validators, then converts to DataFile.
Pros:
- Clean separation of concerns
- No risk to Avro code path
- Easy to test independently
Cons:
- Significant code duplication (all fields defined twice)
- Maintenance burden (keep two classes in sync)
- Conversion overhead
- I've prototyped this here and it's quite verbose
Example:
class RestContentFile(IcebergBaseModel):
# All fields with validators...
content: str # Validates and converts to our content enum
partition: list[Any] # Unbound values
def to_datafile(self) -> DataFile:
# Manual conversion logic...
2. Make DataFile Pydantic
Then it could parse JSON directly with pydantic.
The Challenge with this is that DataFile is coupled to Avro for fields, and extends Record. the Avro reader constructs objects with positional args like DataFile(None, None, ...) then fills by index. We'd need to converge here.
3. Manual parsing
Transform raw JSON dict manually and construct DataFile without Pydantic.
Pros:
- No duplication
- Full control over conversion
- Simple and don't need to mess with existing avro functionality
Cons:
- Lose Pydantic's validation benefits
Reccomendation
I'm Leaning towards B, as it would reduce a lot of duplication. However, it seems can't directly extend both Record and BaseModel due to a metaclass conflict.
I'm Leaning towards option 2 since it would reduce a lot of duplication. However, we can't directly extend both Record and BaseModel due to a metaclass conflict, but we can implement the same StructProtocol interface:
class DataFile(IcebergBaseModel):
content: DataFileContent = Field(default=DataFileContent.DATA)
file_path: str = Field(alias="file-path")
file_format: FileFormat = Field(alias="file-format")
# fields with validators for pydantic conversion
# Field order must match DATA_FILE_TYPE for Avro StructProtocol compatibility.
# The Avro reader/writer accesses fields by position, not name.
_FIELD_ORDER: ClassVar[tuple[str, ...]] = ("content", "file_path", ...)
def __new__(cls, *args, **kwargs):
if args and not kwargs:
# Positional args from Avro reader and bypass validation
return cls.model_construct(**dict(zip(cls._FIELD_ORDER, args)))
return super().__new__(cls)
# StructProtocol interface
def __getitem__(self, pos: int):
return getattr(self, self._FIELD_ORDER[pos])
def __setitem__(self, pos: int, value):
setattr(self, self._FIELD_ORDER[pos], value)
def __len__(self):
return len(self._FIELD_ORDER)
But ultimately, I wanted to get input before making changes since this touches a core model. Open to suggestions on the approach.
cc: @Fokko @kevinjqliu @HonahX
- Linguagem predominante
- Python
- Estrelas
- 1.2k
- Forks
- 618
- Merge médio
- 1d 18h
- PRs com merge (30d)
- 70
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Sem guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de apache/iceberg-python
-
PyArrowFileIO: every small S3 write is a 3-request multipart upload; expose allow_delayed_openAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
apache/iceberg-python#4093 ·
Mantenedores costumam responder em até 1 dia
-
View does not expose metadata_location: RestCatalog.load_view discards it from the server's responseTalvez já em andamento @Soumo-git-hub assumiu há 4 dias. Abertakind:bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
apache/iceberg-python#4073 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
apache/iceberg-python#4010 · 3 comentários · 1 reação ·
Mantenedores costumam responder em até 1 dia
-
to_bytes silently rescales a Decimal with a negative scaleTalvez já em andamento @Rodrigo-Palma assumiu há 23 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
apache/iceberg-python#3996 ·
Mantenedores costumam responder em até 1 dia
-
Deletion vector bitmap count is read from the blob and used as a loop bound without validationTalvez já em andamento @ghoshp83 assumiu há 24 dias. Abertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
apache/iceberg-python#3979 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de apache/iceberg-python
Issues semelhantes
-
Broken links found in docsAbertadocs pydanty:is-working
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
pydantic/pydantic-ai#10113 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 77/100
GreedyBear-Project/GreedyBear#1727 ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
ARM-software/CMSIS-DSP#354 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
kiat/codeAssist#391 ·
-
needs triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 83/100
darnitdevorg/darnit#587 ·
Mantenedores costumam responder em até 1 dia