当前位置: 首页>>代码示例>>Java>>正文


Java StreamSchema类代码示例

本文整理汇总了Java中com.ibm.streams.operator.StreamSchema的典型用法代码示例。如果您正苦于以下问题:Java StreamSchema类的具体用法?Java StreamSchema怎么用?Java StreamSchema使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StreamSchema类属于com.ibm.streams.operator包,在下文中一共展示了StreamSchema类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isValidTupleToAvroMapping

import com.ibm.streams.operator.StreamSchema; //导入依赖的package包/类
public static boolean isValidTupleToAvroMapping(String tupleSchemaName, StreamSchema tupleSchema, Schema avroSchema)
		throws Exception {
	boolean validMapping = true;
	LOGGER.log(TraceLevel.TRACE,
			"Checking attributes in tuple schema " + tupleSchemaName + ": " + tupleSchema.getAttributeNames());
	for (String attributeName : tupleSchema.getAttributeNames()) {
		Attribute attribute = tupleSchema.getAttribute(attributeName);
		Field avroField = avroSchema.getField(attributeName);
		if (avroField != null)
			validMapping = validMapping
					& isValidAttributeToAvroMapping(attributeName, attribute.getType(), avroField.schema());
		else
			LOGGER.log(TraceLevel.INFO, "Attribute " + attributeName + " in schema " + tupleSchemaName
					+ " does not have a corresponding field in the Avro schema. It will not be mapped.");
	}
	return validMapping;
}
 
开发者ID:IBMStreams,项目名称:streamsx.avro,代码行数:18,代码来源:TupleToAvroConverter.java

示例2: checkOutputAttributeRuntime

import com.ibm.streams.operator.StreamSchema; //导入依赖的package包/类
@ContextCheck(compile=false)
public static void checkOutputAttributeRuntime(OperatorContextChecker checker) {
	
	OperatorContext context = checker.getOperatorContext();
	StreamSchema schema = context.getStreamingOutputs().get(0).getStreamSchema();
	Attribute resultAttribute = schema.getAttribute(ANALYSISRESULT_ATTRIBUTE);
	
	//make sure that the output attribute is the right type based on the type of analysis
	String type = context.getParameterValues("analysisType").get(0);
	
	if(type.equals(AnalysisType.Prediction.name())) {
		if( resultAttribute.getType().getMetaType() != MetaType.FLOAT64) {
			tracer.log(TraceLevel.ERROR, "TRACE_M_WRONG_TYPE_ALS", new Object[]{"Prediction", "float64", resultAttribute.getType()});
			checker.setInvalidContext();
		}
	}
	else if(!isList(resultAttribute, Integer.class)) {
		tracer.log(TraceLevel.ERROR, "TRACE_M_WRONG_TYPE_ALS", new Object[]{type, "list<int32>", resultAttribute.getType()});
		checker.setInvalidContext();
	}
}
 
开发者ID:IBMStreams,项目名称:streamsx.sparkMLLib,代码行数:22,代码来源:SparkCollaborativeFilteringALS.java

示例3: checkControlPortInputAttribute

import com.ibm.streams.operator.StreamSchema; //导入依赖的package包/类
@ContextCheck
public static void checkControlPortInputAttribute(OperatorContextChecker checker) {
	OperatorContext context = checker.getOperatorContext();
	
	if(context.getNumberOfStreamingInputs() == 2) {
		StreamSchema schema = context.getStreamingInputs().get(1).getStreamSchema();
		
		//the first attribute must be of type rstring
		Attribute jsonAttr = schema.getAttribute(0);
		
		//check if the output attribute is present where the result will be stored
		if(jsonAttr != null && jsonAttr.getType().getMetaType() != MetaType.RSTRING) {
			tracer.log(TraceLevel.ERROR, "COMPILE_M_WRONG_TYPE", jsonAttr.getType());
			checker.setInvalidContext();
		}
	}
}
 
开发者ID:IBMStreams,项目名称:streamsx.sparkMLLib,代码行数:18,代码来源:AbstractSparkMLlibOperator.java

示例4: checkOutputAttribute

import com.ibm.streams.operator.StreamSchema; //导入依赖的package包/类
/**
 * Compile time to check to ensure that the output schema contains an attribute called
 * 'analysisResult'. The type of the attribute depends on the specific type of the
 * operator and is handled by the appropriate derived class.
 */
@ContextCheck
public static void checkOutputAttribute(OperatorContextChecker checker) {
	OperatorContext context = checker.getOperatorContext();
	
	if(context.getNumberOfStreamingOutputs() == 1) {
		StreamSchema schema = context.getStreamingOutputs().get(0).getStreamSchema();
		Attribute resultAttribute = schema.getAttribute(ANALYSISRESULT_ATTRIBUTE);
		
		//check if the output attribute is present where the result will be stored
		if(resultAttribute == null) {
			tracer.log(TraceLevel.ERROR, "COMPILE_M_MISSING_ATTRIBUTE", new Object[]{ ANALYSISRESULT_ATTRIBUTE});
			checker.setInvalidContext();
		}
	}
}
 
开发者ID:IBMStreams,项目名称:streamsx.sparkMLLib,代码行数:21,代码来源:AbstractSparkMLlibOperator.java

示例5: fixParameters

import com.ibm.streams.operator.StreamSchema; //导入依赖的package包/类
static Map<String,? extends Object> fixParameters(Map<String,? extends Object> params) {
    if (params == null)
        return null;
    
    Map<String,Object> fp = new HashMap<>(params);
    
    // Iterator over params as we may modify fp
    for (String name : params.keySet()) {
        Object value = fp.get(name);
        if (value instanceof StreamSchema) {
            fp.put(name, JParamTypes.create(TYPE_SPLTYPE, ((StreamSchema) value).getLanguageType()));
        } else if (value instanceof Attribute) {
            fp.put(name, JParamTypes.create(TYPE_ATTRIBUTE, ((Attribute) value).getName()));
        }
    }
    return fp;
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:18,代码来源:OpAPIUtil.java

示例6: getSPLMapping

import com.ibm.streams.operator.StreamSchema; //导入依赖的package包/类
public static SPLMapping<?> getSPLMapping(StreamSchema schema) {

        if (STRING.equals(schema)) {
            return SPLMapping.JavaString;
        }
        if (JAVA_OBJECT.equals(schema)) {
            return new SPLJavaObject(schema);
        }
        if (BLOB.equals(schema)) {
            return SPLMapping.JavaBlob;
        }
        if (XML.equals(schema)) {
            return SPLMapping.JavaXML;
        }

        return new SPLTuple(schema);
    }
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:18,代码来源:Schemas.java

示例7: testSPLContentsGood

import com.ibm.streams.operator.StreamSchema; //导入依赖的package包/类
@Test
public void testSPLContentsGood() throws Exception {
    final Topology topology = new Topology();
    TStream<String> source = topology.strings("A", "B", "C", "D");
    StreamSchema schema = SPLSchemas.STRING.extend("int32", "id");
    SPLStream tested = SPLStreams.convertStream(source, (s,t) -> {t.setString(0, s); t.setInt(1, s.charAt(0)); return t;}, schema);
    
    
    ExpectedTuples expected = new ExpectedTuples(schema);
    int id = "A".charAt(0);
    expected.addAsTuple(new RString("A"), id);
    expected.addAsTuple(new RString("B"), ++id);
    expected.addAsTuple(new RString("C"), ++id);
    expected.addAsTuple(new RString("D"), ++id);

    Condition<List<Tuple>> contents = expected.contents(tested);

    boolean passed = complete(topology.getTester(), contents, 10, TimeUnit.SECONDS);
    assertTrue(contents.toString(), contents.valid());
    assertTrue(passed);
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:22,代码来源:ConditionTest.java

示例8: testSPLContentsBad

import com.ibm.streams.operator.StreamSchema; //导入依赖的package包/类
@Test
public void testSPLContentsBad() throws Exception {
    final Topology topology = new Topology();
    TStream<String> source = topology.strings("A", "B", "C", "D");
    StreamSchema schema = SPLSchemas.STRING.extend("int32", "id");
    SPLStream tested = SPLStreams.convertStream(source, (s,t) -> {t.setString(0, s); t.setInt(1, s.charAt(0)); return t;}, schema);
    
    
    ExpectedTuples expected = new ExpectedTuples(schema);
    int id = "A".charAt(0);
    expected.addAsTuple(new RString("A"), id);
    expected.addAsTuple(new RString("B"), ++id);
    expected.addAsTuple(new RString("C"), 1241241);
    expected.addAsTuple(new RString("D"), ++id);

    Condition<List<Tuple>> contents = expected.contents(tested);

    boolean passed = complete(topology.getTester(), contents, 10, TimeUnit.SECONDS);
    assertFalse(passed);

    assertFalse(contents.toString(), contents.valid());
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:23,代码来源:ConditionTest.java

示例9: testConsistentPeriodic

import com.ibm.streams.operator.StreamSchema; //导入依赖的package包/类
@Test
public void testConsistentPeriodic() throws Exception {
    Topology topology = new Topology("testConsistentPeriodic");
    
    StreamSchema schema = Type.Factory.getStreamSchema("tuple<uint64 id>");
    Map<String,Object> params = new HashMap<>();
    params.put("iterations", 200);
    params.put("period", 0.05);
    
    SPLStream b = SPL.invokeSource(topology, "spl.utility::Beacon", params, schema);
    
    ConsistentRegionConfig config = periodic(2);
    assertSame(b, b.setConsistent(config));
    
    Condition<Long> atLeast = topology.getTester().atLeastTupleCount(b, 200);
    complete(topology.getTester(), atLeast, 80, TimeUnit.SECONDS);
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:18,代码来源:ConsistentRegionTest.java

示例10: testConsistentOperatorDriven

import com.ibm.streams.operator.StreamSchema; //导入依赖的package包/类
@Test
public void testConsistentOperatorDriven() throws Exception {
    Topology topology = new Topology("testConsistentOperatorDriven");
    
    StreamSchema schema = Type.Factory.getStreamSchema("tuple<uint64 id>");
    Map<String,Object> params = new HashMap<>();
    params.put("iterations", 300);
    params.put("triggerCount", SPL.createValue(37, Type.MetaType.UINT32));
    
    SPLStream b = SPL.invokeSource(topology, "spl.utility::Beacon", params, schema);
    
    ConsistentRegionConfig config = ConsistentRegionConfig.operatorDriven();
    assertSame(b, b.setConsistent(config));
    
    Condition<Long> atLeast = topology.getTester().atLeastTupleCount(b, 300);
    complete(topology.getTester(), atLeast, 40, TimeUnit.SECONDS);
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:18,代码来源:ConsistentRegionTest.java

示例11: checkFileAttributeName

import com.ibm.streams.operator.StreamSchema; //导入依赖的package包/类
/**
 * Check that the fileAttributeName parameter is an attribute of the right
 * type.
 * 
 * @param checker
 */
@ContextCheck(compile = false)
public static void checkFileAttributeName(OperatorContextChecker checker) {
	StreamSchema inputSchema = checker.getOperatorContext()
			.getStreamingInputs().get(0).getStreamSchema();
	List<String> fileAttrNameList = checker.getOperatorContext()
			.getParameterValues(IHdfsConstants.PARAM_FILE_NAME_ATTR);
	if (fileAttrNameList == null || fileAttrNameList.size() == 0) {
		// Nothing to check, because the parameter doesn't exist.
		return;
	}

	String fileAttrName = fileAttrNameList.get(0);
	Attribute fileAttr = inputSchema.getAttribute(fileAttrName);
	if (fileAttr == null) {
		checker.setInvalidContext(Messages.getString("HDFS_SINK_NO_ATTRIBUTE"), 
				new Object[] { fileAttrName });
	}
	if (MetaType.RSTRING != fileAttr.getType().getMetaType()
			&& MetaType.USTRING != fileAttr.getType().getMetaType()) {
		checker.setInvalidContext(
				Messages.getString("HDFS_SINK_INVALID_ATTR_FILENAME", fileAttr.getType().getMetaType()), 
				new Object[] {});
	}
}
 
开发者ID:IBMStreams,项目名称:streamsx.hdfs,代码行数:31,代码来源:HDFS2FileSink.java

示例12: checkInputPortSchema

import com.ibm.streams.operator.StreamSchema; //导入依赖的package包/类
@ContextCheck()
public static void checkInputPortSchema(OperatorContextChecker checker) {
	List<StreamingInput<Tuple>> streamingInputs = checker.getOperatorContext().getStreamingInputs();
	if (streamingInputs.size() > 0) {
		StreamSchema inputSchema = streamingInputs.get(0).getStreamSchema();
		if (inputSchema.getAttributeCount() > 1) {
			checker.setInvalidContext(
					Messages.getString("HDFS_DS_INVALID_INPUT_PORT"), 
					null);
		}

		if (inputSchema.getAttribute(0).getType().getMetaType() != MetaType.RSTRING) {
			checker.setInvalidContext(Messages.getString("HDFS_DS_INVALID_ATTRIBUTE", 
					 inputSchema.getAttribute(0).getType().getMetaType()), null);
		}

		ConsistentRegionContext crContext = checker.getOperatorContext().getOptionalContext(
				ConsistentRegionContext.class);
		if (crContext != null) {
			LOGGER.log( LogLevel.WARNING, Messages.getString("HDFS_DS_CONSISTENT_REGION_NOT_SUPPORTED")); 
		}
	}

}
 
开发者ID:IBMStreams,项目名称:streamsx.hdfs,代码行数:25,代码来源:HDFS2DirectoryScan.java

示例13: convertTupleToAvro

import com.ibm.streams.operator.StreamSchema; //导入依赖的package包/类
public static GenericRecord convertTupleToAvro(Tuple tuple, StreamSchema streamSchema, Schema avroSchema) {
	GenericRecord datum = new GenericData.Record(avroSchema);
	for (String attributeName : streamSchema.getAttributeNames()) {
		Attribute attribute = streamSchema.getAttribute(attributeName);
		Object tupleAttribute = tuple.getObject(attributeName);
		Field avroField = avroSchema.getField(attributeName);
		// If there is an Avro field associated with this attribute, convert
		if (avroField != null)
			datum.put(attributeName,
					convertAttributeToAvro(attributeName, tupleAttribute, attribute.getType(), avroField.schema()));
	}
	return datum;
}
 
开发者ID:IBMStreams,项目名称:streamsx.avro,代码行数:14,代码来源:TupleToAvroConverter.java

示例14: checkOutputAttributeType

import com.ibm.streams.operator.StreamSchema; //导入依赖的package包/类
/**
 * Check to ensure that an analysisResult attribute of type int32 is present on the output schema
 */
@ContextCheck
public static void checkOutputAttributeType(OperatorContextChecker checker) {
	
	OperatorContext context = checker.getOperatorContext();
	StreamSchema schema = context.getStreamingOutputs().get(0).getStreamSchema();
	Attribute resultAttribute = schema.getAttribute(ANALYSISRESULT_ATTRIBUTE);
	
	if(resultAttribute != null && resultAttribute.getType().getMetaType() != MetaType.INT32) {
		tracer.log(TraceLevel.ERROR, "COMPILE_M_WRONG_TYPE_FULL", new Object[]{ANALYSISRESULT_ATTRIBUTE, "int32", resultAttribute.getType()});
		checker.setInvalidContext();
	}
}
 
开发者ID:IBMStreams,项目名称:streamsx.sparkMLLib,代码行数:16,代码来源:SparkClusteringKMeans.java

示例15: checkOutputAttributeType

import com.ibm.streams.operator.StreamSchema; //导入依赖的package包/类
/**
 * Check to ensure that an analysisResult attribute of type float64 is present on the output schema
 */
@ContextCheck
public static void checkOutputAttributeType(OperatorContextChecker checker) {
	
	OperatorContext context = checker.getOperatorContext();
	StreamSchema schema = context.getStreamingOutputs().get(0).getStreamSchema();
	Attribute resultAttribute = schema.getAttribute(ANALYSISRESULT_ATTRIBUTE);
	
	if(resultAttribute != null && resultAttribute.getType().getMetaType() != MetaType.FLOAT64) {
		tracer.log(TraceLevel.ERROR, "COMPILE_M_WRONG_TYPE_FULL", new Object[]{ANALYSISRESULT_ATTRIBUTE, "float64", resultAttribute.getType()});
		checker.setInvalidContext();
	}
}
 
开发者ID:IBMStreams,项目名称:streamsx.sparkMLLib,代码行数:16,代码来源:AbstractSparkMLlibListToDoubleOperator.java


注:本文中的com.ibm.streams.operator.StreamSchema类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。