-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CALCITE-6690] Refactor the Arrow adapter type system #4052
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,7 +103,8 @@ private Schema makeArrowDateTypeSchema() { | |
FieldType doubleType = | ||
FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)); | ||
FieldType booleanType = FieldType.nullable(new ArrowType.Bool()); | ||
FieldType decimalType = FieldType.nullable(new ArrowType.Decimal(10, 2, 128)); | ||
FieldType decimalType = FieldType.nullable(new ArrowType.Decimal(12, 2, 128)); | ||
FieldType decimalType2 = FieldType.nullable(new ArrowType.Decimal(12, 3, 128)); | ||
FieldType dateType = FieldType.nullable(new ArrowType.Date(DateUnit.DAY)); | ||
|
||
childrenBuilder.add(new Field("tinyIntField", tinyIntType, null)); | ||
|
@@ -116,6 +117,7 @@ private Schema makeArrowDateTypeSchema() { | |
childrenBuilder.add(new Field("booleanField", booleanType, null)); | ||
childrenBuilder.add(new Field("decimalField", decimalType, null)); | ||
childrenBuilder.add(new Field("dateField", dateType, null)); | ||
childrenBuilder.add(new Field("decimalField2", decimalType2, null)); | ||
|
||
return new Schema(childrenBuilder.build(), null); | ||
} | ||
|
@@ -237,35 +239,38 @@ public void writeArrowDataType(File file) throws IOException { | |
vectorSchemaRoot.setRowCount(numRows); | ||
for (Field field : vectorSchemaRoot.getSchema().getFields()) { | ||
FieldVector vector = vectorSchemaRoot.getVector(field.getName()); | ||
switch (vector.getMinorType()) { | ||
case TINYINT: | ||
switch (field.getName()) { | ||
case "tinyIntField": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a necessary change? What is the difference between decimalField2 and decimalField? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Required, the scale of decimalfield and decimalfiled2 are different, one is 2, the other is 3, the main purpose is to capture the accuracy of whether it is effective |
||
tinyIntField(vector, numRows); | ||
break; | ||
case SMALLINT: | ||
case "smallIntField": | ||
smallIntFiled(vector, numRows); | ||
break; | ||
case INT: | ||
case "intField": | ||
intField(vector, numRows); | ||
break; | ||
case FLOAT4: | ||
case "floatField": | ||
floatField(vector, numRows); | ||
break; | ||
case VARCHAR: | ||
case "stringField": | ||
varCharField(vector, numRows); | ||
break; | ||
case BIGINT: | ||
case "longField": | ||
longField(vector, numRows); | ||
break; | ||
case FLOAT8: | ||
case "doubleField": | ||
doubleField(vector, numRows); | ||
break; | ||
case BIT: | ||
case "booleanField": | ||
booleanField(vector, numRows); | ||
break; | ||
case DECIMAL: | ||
case "decimalField": | ||
decimalField(vector, numRows); | ||
break; | ||
case DATEDAY: | ||
case "decimalField2": | ||
decimalField2(vector, numRows); | ||
break; | ||
case "dateField": | ||
dateField(vector, numRows); | ||
break; | ||
default: | ||
|
@@ -386,6 +391,17 @@ private void decimalField(FieldVector fieldVector, int rowCount) { | |
fieldVector.setValueCount(rowCount); | ||
} | ||
|
||
private void decimalField2(FieldVector fieldVector, int rowCount) { | ||
DecimalVector decimalVector = (DecimalVector) fieldVector; | ||
decimalVector.setInitialCapacity(rowCount); | ||
decimalVector.allocateNew(); | ||
for (int i = 0; i < rowCount; i++) { | ||
decimalVector.set(i, this.decimalValue.setScale(3)); | ||
this.decimalValue = this.decimalValue.add(BigDecimal.ONE); | ||
} | ||
fieldVector.setValueCount(rowCount); | ||
} | ||
|
||
private void dateField(FieldVector fieldVector, int rowCount) { | ||
DateDayVector dateDayVector = (DateDayVector) fieldVector; | ||
dateDayVector.setInitialCapacity(rowCount); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think enums are preferable, since they are typechecked by the compiler.
A Class can be anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Later, I may dynamically pass some parameters according to the data type of arrow, which is difficult to achieve through enumeration.
e.g.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why later if you are refactoring the code now?
Do it correctly the first time.
I am suggesting to have 3 arguments for the enum constructor: Class, precision, scale.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mihaibudiu Sorry for the late reply, you are right. I looked at the arrow types and it seems that Class, precision, and scale are sufficient.
I will finish this work on the weekend
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mihaibudiu Hi. I have a question, how to dynamically pass parameters in enumeration class? Precision and scale are not constants for decimal, timestamp and other types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I understand the question.
There are lots of enum classes with parameters in the codebase.
See https://github.com/apache/calcite/blob/main/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Primitive.java for example