Skip to content

Commit 77e78f4

Browse files
committed
Add ability to not read blobs
1 parent 31344aa commit 77e78f4

File tree

4 files changed

+58
-6
lines changed

4 files changed

+58
-6
lines changed

commons-hpcc/src/main/java/org/hpccsystems/commons/ecl/FieldDef.java

+1
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ public boolean isBlob()
344344

345345
/**
346346
* Sets the blob flag.
347+
* @param blob is the field a blob?
347348
*/
348349
public void setIsBlob(boolean blob)
349350
{

commons-hpcc/src/main/java/org/hpccsystems/commons/ecl/RecordDefinitionTranslator.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class RecordDefinitionTranslator
3737

3838
private static final String ESP_TYPE_NAME_PREFIX = "ty";
3939

40+
private static final int BLOB_LENGTH = 8;
4041
private static final int FLAG_UNSIGNED = 256;
4142
private static final int FLAG_UNKNOWN_SIZE = 1024;
4243
private static final int TYPE_ID_MASK = 0xff; // 0x7fff & ~FLAG_UNKNOWN_SIZE & ~FLAG_UNSIGNED;
@@ -730,7 +731,7 @@ private static int getJsonTypeDefinition(FieldDef field, HashMap<Integer, Intege
730731

731732
JSONObject typeDef = new JSONObject();
732733
typeDef.put("fieldType", type_blob);
733-
typeDef.put("length", 8);
734+
typeDef.put("length", BLOB_LENGTH);
734735
typeDef.put("child", nonBlobTypeName);
735736

736737
int newTypeIndex = typeDefinitions.size();

dfsclient/src/main/java/org/hpccsystems/dfs/client/BinaryRecordReader.java

+30
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,36 @@ private Object parseRecord(FieldDef recordDef, IRecordBuilder recordBuilder, boo
558558
for (int fieldIndex = 0; fieldIndex < recordDef.getNumDefs(); fieldIndex++)
559559
{
560560
FieldDef fd = recordDef.getDef(fieldIndex);
561+
if (fd.isBlob())
562+
{
563+
// If we encounter a blob field, we only have access to the blob file location
564+
// So read that location and construct a default value field
565+
long blobFileLoc = (long) getUnsigned(8, true);
566+
try
567+
{
568+
switch (fd.getFieldType())
569+
{
570+
case BINARY:
571+
recordBuilder.setFieldValue(fieldIndex, new byte[0]);
572+
continue;
573+
case STRING:
574+
case VAR_STRING:
575+
recordBuilder.setFieldValue(fieldIndex, "");
576+
continue;
577+
case SET:
578+
case DATASET:
579+
recordBuilder.setFieldValue(fieldIndex, new ArrayList<Object>());
580+
continue;
581+
default:
582+
throw new UnparsableContentException("Unexpected blob type: " + fd.getFieldType() + " for field: " + fd.getFieldName());
583+
}
584+
}
585+
catch (IllegalAccessException e)
586+
{
587+
throw new UnparsableContentException("Unable to set field value for field: " + fd.getFieldName() + " with error: " + e.getMessage());
588+
}
589+
}
590+
561591
Object fieldValue = null;
562592
switch (fd.getFieldType())
563593
{

dfsclient/src/main/java/org/hpccsystems/dfs/client/HPCCFile.java

+25-5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class HPCCFile implements Serializable
5252
private DataPartition[] dataParts;
5353
private DataPartition tlkPartition = null;
5454
private boolean useTLK = true;
55+
private boolean readBlobs = true;
5556
private PartitionProcessor partitionProcessor = null;
5657
private long dataPartsCreationTimeMS = -1;
5758

@@ -241,7 +242,7 @@ private void updateProjectedRecordDef() throws Exception
241242
{
242243
this.projectedRecordDefinition = this.columnPruner.pruneRecordDefinition(this.recordDefinition);
243244

244-
// By default project all sub-integer types to standard integers
245+
// By default project all sub-integer types to standard integers and all blobs to non-blobs
245246
for (int i = 0; i < this.projectedRecordDefinition.getNumDefs(); i++)
246247
{
247248
FieldDef field = this.projectedRecordDefinition.getDef(i);
@@ -250,10 +251,11 @@ private void updateProjectedRecordDef() throws Exception
250251
field.setSourceType(HpccSrcType.LITTLE_ENDIAN);
251252
}
252253

253-
// if (field.isBlob())
254-
// {
255-
// field.setIsBlob(false);
256-
// }
254+
// Project blobs to non-blobs, otherwise we will only get back the file position of the blob
255+
if (readBlobs && field.isBlob())
256+
{
257+
field.setIsBlob(false);
258+
}
257259
}
258260
}
259261

@@ -367,6 +369,24 @@ public HPCCFile setUseTLK(boolean useTLK)
367369
return this;
368370
}
369371

372+
/**
373+
* Sets the read blobs options
374+
* Note: Blobs are read by default, on older HPCC systems reading blobs can cause issues reading blobs should be disabled for these systems.
375+
*
376+
* @param readBlobs should blobs be read
377+
*
378+
* @return this file
379+
*/
380+
public HPCCFile setReadBlobs(boolean readBlobs)
381+
{
382+
this.readBlobs = readBlobs;
383+
384+
// Force the data parts to be re-created
385+
this.dataParts = null;
386+
387+
return this;
388+
}
389+
370390
/**
371391
* Gets the filter.
372392
*

0 commit comments

Comments
 (0)