Skip to content

Commit

Permalink
Removing record naming from each language.
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelbranco80 committed Feb 3, 2025
1 parent 341c12f commit cf75fc1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
package com.rawlabs.snapi.compiler

import com.google.protobuf.ByteString
import com.rawlabs.compiler.utils.RecordFieldsNaming
import com.rawlabs.compiler.{
AutoCompleteResponse,
CompilerService,
Expand Down Expand Up @@ -766,21 +765,16 @@ class SnapiCompilerService(engineDefinition: (Engine, Boolean))(implicit protect
.build()

case SnapiRecordType(attributes, _) =>
// We need to make sure that the field names are distinct
val keys = new java.util.Vector[String]
attributes.foreach(a => keys.add(a.idn))
val distincted = RecordFieldsNaming.makeDistinct(keys).asScala

// Build a RawRecord
val recordAttrs = attributes.zip(distincted).map {
case (att, distinctName) =>
val recordAttrs = attributes.map {
case att =>
val fieldName = att.idn
val memberVal = v.getMember(fieldName)
val fieldValue = fromTruffleValue(
memberVal,
att.tipe.asInstanceOf[SnapiTypeWithProperties]
)
ValueRecordField.newBuilder().setName(distinctName).setValue(fieldValue).build()
ValueRecordField.newBuilder().setName(fieldName).setValue(fieldValue).build()
}
com.rawlabs.protocol.raw.Value
.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ package com.rawlabs.sql.compiler.writers

import com.fasterxml.jackson.databind.{JsonNode, ObjectMapper}
import com.rawlabs.compiler._
import com.rawlabs.compiler.utils.RecordFieldsNaming
import com.rawlabs.protocol.raw.{
Value,
ValueBool,
Expand Down Expand Up @@ -132,13 +131,9 @@ class TypedResultSetRawValueIterator(

import TypedResultSetRawValueIterator._

private val (attributes, distinctNames) = t match {
private val attributes = t match {
// We assume t is something like RawIterableType(RawRecordType(atts, _, _), _, _)
case RawIterableType(RawRecordType(atts, _, _), _, _) =>
val names = new java.util.Vector[String]()
atts.foreach(a => names.add(a.idn))
val distincted = RecordFieldsNaming.makeDistinct(names)
(atts, distincted)
case RawIterableType(RawRecordType(atts, _, _), _, _) => atts
case _ => throw new IllegalArgumentException(
s"TypedResultSetRawValueIterator can only handle Iterable of Record. Got: $t"
)
Expand Down Expand Up @@ -169,7 +164,7 @@ class TypedResultSetRawValueIterator(

// Each row is a RawRecord
val rowAttrs = for (i <- attributes.indices) yield {
val fieldName = distinctNames.get(i)
val fieldName = attributes(i).idn
val fieldType = attributes(i).tipe
val fieldValue = readValue(resultSet, i + 1, fieldType)
ValueRecordField.newBuilder().setName(fieldName).setValue(fieldValue).build()
Expand Down

0 comments on commit cf75fc1

Please sign in to comment.