Esempio n. 1
0
func transactFile(tx *transactor.Transaction, r io.Reader, format, compression string) {
	var (
		err error
	)

	// Apply decompression.
	if compression != "" {
		logrus.Debugf("transact: applying %s decompression", compression)

		if r, err = origins.Decompressor(r, compression); err != nil {
			logrus.Fatalf("transact: %s", err)
		}
	}

	// Wrap in a reader to handle carriage returns before passing
	// it into the format reader.
	r = origins.NewUniversalReader(r)

	var iter origins.Iterator

	switch format {
	case "csv":
		iter = origins.NewCSVReader(r)
	default:
		logrus.Fatal("transact: unsupported file format", format)
	}

	if _, err = origins.Copy(iter, tx); err != nil {
		logrus.Fatal("transact:", err)
	}
}
Esempio n. 2
0
func TestInitSchema(t *testing.T) {
	data, _ := testutil.Asset("assets/origins.csv")

	iter := origins.NewCSVReader(bytes.NewBuffer(data))

	schema := Init("origins.attrs", iter)

	attrs := schema.Attrs()

	assert.Equal(t, 18, len(attrs))
}
Esempio n. 3
0
func setup() storage.Engine {
	engine, _ := origins.Init("memory", nil)

	data, _ := testutil.Asset("assets/origins.csv")

	iter := origins.NewCSVReader(bytes.NewBuffer(data))

	tx, _ := transactor.New(engine, transactor.Options{})

	// Write the facts.
	if _, err := origins.Copy(iter, tx); err != nil {
		panic(err)
	}

	tx.Commit()

	return engine
}
Esempio n. 4
0
func buildIter(t *testing.T) origins.Iterator {
	buf := bytes.NewBufferString(testData)

	return origins.NewCSVReader(buf)
}
Esempio n. 5
0
		// Get a stdout pipe from the command for the reader to consume.
		stdout, err := pcmd.StdoutPipe()

		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		var (
			iterator origins.Iterator
			writer   origins.Writer
		)

		// Data written to the buffer are converted into facts, normalized, and
		// copied to the CSV writer.
		iterator = origins.NewCSVReader(stdout)

		// Facts are written to stdout.
		writer = origins.NewCSVWriter(os.Stdout)

		// Modify the fact before writing using the passed arguments.
		// TODO: there is a overlap with the transactor.
		writer = &modWriter{
			writer: writer,
			modifier: func(f *origins.Fact) {
				if f.Domain == "" {
					f.Domain = domain
				}

				f.Operation = operation