Skip to content

Commit

Permalink
Allow the inner type to be assignable not equal
Browse files Browse the repository at this point in the history
  • Loading branch information
bratseth committed Feb 2, 2025
1 parent 1a0d641 commit 691fea4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Class getValueClass() {
@Override
public FieldPath buildFieldPath(String remainFieldName)
{
if (remainFieldName.length() > 0 && remainFieldName.charAt(0) == '[') {
if (!remainFieldName.isEmpty() && remainFieldName.charAt(0) == '[') {
int endPos = remainFieldName.indexOf(']');
if (endPos == -1) {
throw new IllegalArgumentException("Array subscript must be closed with ]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ public PrimitiveDataType getPrimitiveType() {

@Override
public boolean isValueCompatible(FieldValue value) {
if (!(value instanceof CollectionFieldValue)) {
return false;
}
CollectionFieldValue<?> cfv = (CollectionFieldValue<?>) value;
return equals(cfv.getDataType());
if (!(value instanceof CollectionFieldValue<?> collectionValue)) return false;
if (collectionValue.getDataType().getClass() != this.getClass()) return false;
return collectionValue.getDataType().getNestedType().isAssignableTo(this.getNestedType());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,18 @@ public void testArrayEmbedTo2MappedTensor() {
sparse2DTensor.getTensor().get());
}

@Test
public void testIt() {
var tester = new EmbeddingScriptTester(Map.of("emb1", new EmbeddingScriptTester.MockMappedEmbedder("myDocument.sections_embeddings")));
var expression = tester.expressionFrom("input sections | for_each { ( _ || \"\") } | embed emb1 passage | attribute sections_embeddings | index sections_embeddings");

SimpleTestAdapter adapter = new SimpleTestAdapter();
adapter.createField(new Field("sections", new ArrayDataType(DataType.STRING)));
TensorType tensorType = TensorType.fromSpec("tensor(passage{}, token{})");
var tensorField = new Field("sections_embeddings", new TensorDataType(tensorType));
adapter.createField(tensorField);

expression.verify(new VerificationContext(adapter));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

/**
* @author Simon Thoresen Hult
* @author bratseth
*/
public class ScriptTestCase {

Expand Down

0 comments on commit 691fea4

Please sign in to comment.