text:
Impact of supply chain coordination on honey farmers' income in Tigray, Northern Ethiopia
Abebe Ejigu Alemu2,3,
Miet Maertens1,
Jozef Deckers1,
Hans Bauer4 &
Erik Mathijs1
Most of the literature on vertical coordination and its impact on farm performance and farmer wellbeing deal with high-value or modern food supply chains, including export chains and chains dominated by large international supermarkets or other forms of foreign direct investment. The impact of vertical coordination mechanisms in local food supply chains in developing countries remains underexplored. This paper analyzes the impact of participation of honey producers in the Northern highlands of Tigray, Ethiopia in contracts and marketing cooperatives on their performance and wellbeing. The paper finds positive production and economic gains honey producers obtain from contract engagement. Honey producers under the contract scheme produce more white honey fulfilling the demand of processors, buyers and consumers. Contracting results in higher production due to the better access it causes to technology and skill transfers. Moreover, better conditions contracts offer motivates honey producers to produce more and supply larger to the market.
The transformation of agricultural marketing systems in sub-Saharan Africa remains slow, even after the liberalization and globalization of trade. The rural agricultural marketing system in developing countries fails to adjust and fully respond to changes in the market in terms of quality and quantity (Jayne et al., 2010). As in many countries and regions in sub-Saharan Africa, the marketing system in the rural highlands of Ethiopia does not perform well due to several challenges (Gabre-Madhin, 2001).
The poor economic conditions, the imperfect input and product markets, the large number of smallholders, the high transaction costs in searching buyers, the lack of private sector investment in processing and agri-business and the poor coordination among actors in the agrifood supply chain are cited as the factors that restrain the performance of food supply chains in developing countries (Dorward et al., 22007; Gabre-Madhin, 2001). Institutions for market information, standardizing, grading and labeling, and contract enforcement are also weak, which further undermines the performance of the agricultural marketing system. Poor road and communication infrastructure, thin input and output markets, underdeveloped monetary systems are further claimed to affect the rural areas in Africa (Dorward et al., 2007).
Theory and empirical evidence suggest that vertical coordination (VC) can foster the development of smallholder agriculture through the provision of inputs and technology, and the mitigation of transaction costs (Williamson, 1979; Swinnen and Maertens, 2007). Empirical evidence from Eastern Europe, Africa and Latin-America suggests that contracts offer credit, inputs, better prices and extension services which enable growers to be productive and secure better economic benefits (e.g., Minten et al., 2007; Dries et al., 2009; Maertens et al., 2011). Also cooperatives can facilitate the access of smallholder farmers to farm resources, especially for poor farmers. They facilitate access to credit and reap the benefit of significant support from state and other development partners (Key and Runsten, 1999; Bijman and Hu, 2011). Cooperatives can also help empower farmers in terms of collective ownership of farm investment and processing technology (Hendrikse and Bijman, 2002). Marketing cooperatives are also found influencing smallholders' commercialization behavior in Ethiopia and having poverty impact in Rwanda though the results indicate better benefits to larger farmers (Bernard et al. 2008; Francesconi and Nico 2010; Verhofstadt and Maertens, 2014).
Researchers and policy-makers are optimistic about the observed increased VC in food supply chains as it can contribute to the transformation of traditional agricultural practices towards modern supply chains (Abebaw and Haile, 2013). However, the impact of VC on the performance of smallholder farms remains controversial. Empirical evidence from organic coffee producers in Uganda, tomato producers in Senegal, and apple and green onion producers in China have indicated positive income gains of contract-farming (Maertens and Swinnen, 2009; Miyata et al., 2009; Bolwig et al., 2010). The observed increase in smallholders' income is attributed to buyers' commitment for the supply of inputs, technology and extension services; which enables farmers to increase productivity. In China and Uganda farmers under a contracting scheme were found to be efficient as they received extension skills to manage inputs, feed, labor, and capital (Miyata et al., 2009; Bolwig et al. 2010). Furthermore, contract farming leads to better quality produce and premium prices, resulting in larger economic benefits for farmers. Contracting also may reduce transaction costs, and leads to more efficient transactions in food supply chains (Miyata et al., 2009). Furthermore, contracts may channel capital/financial support to farmers to ease expansion of firms (Simmons et al., 2005; Dries et al., 2009). Spillover effects may also contribute to the productivity of smallholder farmers in various developing countries (Schipmann and Qaim, 2010).
In cases where farmers fail to access contracts due to their small size, processors and rural development agencies sometimes supply credit and inputs via cooperatives (Abebaw and Haile 2013; Bernard et al., 2008). Cooperatives or farmers' organizations generally pool resources to facilitate access to specific assets, reduce information asymmetries, empower smallholders in the market, and facilitate organized support from credit and technology suppliers (Bernard et al., 2008; Bijman and Hendrikse, 2003; Bijman and Hu, 2011; Blandon et al., 2009). Cooperatives also lower transactions costs for providing extension services and information (Masakure and Henson, 2005), and facilitate the adoption of new technologies (Nwankwo et al., 2009; Abebaw and Haile 2013).
Despite its wide application in developing countries, contracts are sometimes criticized for exploiting farmers (Singh, 2002). Unequal power relations between contractors and contracted producers can lead to contract conditions in favor of large-scale companies and to the exploitation of farmers. Furthermore, contracts are also accused of eroding the autonomy/flexibility of farmers in making farm decisions (Gillespie and Eidman, 1998; Key, 2004). A much debated issue is the exclusion of the poorest farmers and the smallest farms from contract farming schemes. High administrative costs of contracting with a large number of small producers foster contracting with larger farms. Asset-poor farmers may face difficulties in complying with processor/retailer specific standards and requirements, resulting in the exclusion of poor farmers from contract-farming schemes (Weatherspoon and Reardon, 2003). However, producer-induced organizations such as cooperatives help tackle the exclusion of smallholders and offer significant economic benefits to smallholders (Staal et al., 1997; Takane, 2004; Bijman and Hu, 2011).
Most of the literature on VC and its impact on farm performance and farmer wellbeing deals with so-called high-value or modern food supply chains, including export chains and chains dominated by large international supermarkets or other forms of foreign direct investment. The impact of VC mechanisms (contracts and marketing cooperatives altogether in contrast to spot markets) in local food supply chains in developing countries especially in the Ethiopian context remains underexplored though the challenges in the traditional domestic markets in the African context are well studied (Dorward et al., 2006). Comparative studies on the impact of hybrids, contracts and marketing cooperatives viz. spot market transactions are scare. In this paper, we analyze the impact of participation of honey producers in the Northern highlands of Ethiopia in contracts and cooperatives on their performance and household income. We, thus contribute to the literature on VC by providing evidence from local food chains and provide insights that can inform governmental and development organizations on the realization of pro-poor growth through institutional innovations such as contracts and marketing cooperatives in supply chains in partnership with the private sector.
The practice of beekeeping in Ethiopia is integrated with crop farming and animal husbandry at household level. It is part of the integrated household extension program targeted to diversify household livelihood and income (Egziabher et al. 2013; Legesse, 2014). CSA (2013) reported that there were nearly 5.21 million beehives in Ethiopia, producing 45,100 tons of honey, of which about 38 % was for household consumption, 58 % for the market and the rest for wage payment. Production of honey grows every year; for eg. It grows from 24,000 tons in 1993 to 45,100 tons in 2012. In terms of honey production, the country is ranked 9th in the world which may offer an advantage to capitalize on the subsector (FAO 2015). Honey export has increased from 1.5 tons in 2000, 275 tons in 2010 and more than 730 tons in 2012 (Legesse, 2014). Honey production and marketing in Ethiopia is largely at household level and on spot market bases. However recently, production cooperatives, marketing cooperatives and contract base transactions in the honey subsector are emerging to offer producers with required inputs, technology, market information and market access thereby reducing transaction costs. However, this paper is limited to the impact of contracts and marketing cooperatives on the income of honey producing households in Tigray, Northern Ethiopia.
The rest of the paper is organized as follows. In section two the honey production and marketing system in Ethiopia is briefly reviewed. In the third section the study site is presented and data collection procedures are explained. In the fourth section the coordination mechanisms and performance of honey producers are discussed based on descriptive statistics. The econometric methods and estimation procedures are explained in the fifth section, and econometric results are discussed in the sixth section. The last section ends the paper with conclusions and implications.
Honey Production and Marketing in Ethiopia and Tigray
Honey production has a long tradition in Ethiopia. The practice of beekeeping in Ethiopia is often integrated with crop farming and animal husbandry. In many regions of the country, beekeeping is an important additional income-generating activity for farmers, next to cropping and livestock rearing. Currently, the honey sector is part of the integrated household extension program runn by the government to imprve productivity and increase household income (Egziabher et al. 2013). It is also believed to be one of the subsectors which tend to be inclusive of smallholders in Ethiopia (Paulos, 2012). Apiculture can importantly contribute to the livelihood of rural households, either by providing additional income through honey sale or by providing a high-nutritious food product for household consumption. Honey production is regarded as a poverty reduction strategy and as a tool for combating malnutrition in rural areas of developing countries (Legesse, 2014).
The honey production has grown almost every year from 24,000 tons in 1993 to 45,000 tons in 2013 (FAO, 2015). Most honey (more than 95 %) is produced using traditional beehives. However, traditional beehives produce less than 10 kg of honey/hive/year. The modern beehive provides on average 23 kg of clean honey per hive/year (CSA, 2013). However, modern hives are costly (on average USD 50.00) compared to the locally made traditional hives that costs no more than USD 5.00. CSA (2013) estimated that 38.31 % was for household consumption, 58.49 % was for the market largely for domestic market (more than 98 %) and the rest was used as wage payment. Most of the honey production is carried out by smallholder farmers. It has a prospect of further growth if it is well integrated with the global food chains and supported with relevant inputs and technology. Nearly 4.4 % of the beehives are found in Tigray which accounts for 5.2 % of the total honey production in Ethiopia (CSA 2013). More than 20 % were modern beehives implying more modern beehive technology use in the region (CSA 2013) and the majority of honey is offered to the market (more than 60 %).
There is an increasing trend in the production of honey from modern beehives. Modern beehives and honey extracting technology are mostly supplied by government agencies and non-governmental organizations (e.g., ARDO, REST-local NGO which stands for Relief Society of Tigray, World Vision, the Ethiopian Orthodox and the Catholic Church). For example, in 2008 the Regional Agricultural and Rural Development Office (ARDO) provided 26,676 units of modern beehives to smallholders in Tigray.
Honey export was below 1 % of production up until 2006. However, once the government and development partners have aggressively distributed modern hives, processing companies has acquired more honey supply and expand honey export. The honey export increased from one ton in 2001 to 615 tons in 2010 and 729 tons in 2013. It is destined mainly to Yemen, Sudan, Saudi Arabia and Djibouti before getting the admisiion to penetrate the EU market in 2008 (Gezahegn et al. 2006; Paulos 2012).
The 2010 estimate of honey production in Tigray was 2,768 tons, which accounts for 5.2 % of the total honey production in Ethiopia (CSA, 2013). There were 213,133 beehives in Tigray in 2010. More than 20 % were modern beehives (CSA, 2013) and the majority of honey is offered to the market (more than 60 %). As reported by Melaku et al. (2008), 80 to 90 % of the honey produced in the Atsbi district was marketed, which points to the market-oriented nature of honey production in the region. There is an increasing trend in the production of honey from modern beehives; i.e., 269 tons in 2005 to 1061 tons in 2010. ARDO, NGOs and processors contribute to the expansion of modern beehives in the region.
Most of the honey produced and marketed in Tigray is white honey, while only a small amount of yellow and red honey is produced and marketed. White honey is high value honey that is harvested during the prime season (September to December) and almost entirely sold by farmers. During the dry season, farmers may harvest some honey, but due to the scarcity of flowers and plants, bees mix species result in a change in color for the honey. Part of the yellow and red honey is being kept at home for consumption or medicinal use (Gezahegn et al. 2006; Melaku et al., 2008). To improve honey production and marketing, government and NGOs (like World Vision, SNV-Ethiopia, REST) have intervened to upgrade beehives and extraction process, transfer technology through training and supplying credit and inputs.
As production of honey is largely in the hands of smallholders who own only a few beehives, it offers a small amount to the market from which the majority (about 80 %) is supplied to local mead brewers (Gezahegn et al. 2006; Melaku et al., 2008). The subsector is also facing a number of challenges such as lack of adequate technology, extension services, beekeeping materials and lack of adequate market (Abebe and Ranjitha, 2011).
Nevertheless, to improve honey production and the marketing system in the country, government and other non-governmental development organizations (like World Vision, SNV-Ethiopia, REST) have intervened to a great extent in terms of modernizing the beehives and the extraction process, transferring technology through training, upgrading the honey value chains, and supplying credit and other inputs (Paulos 2012).
Honey is marketed mostly on spot markets, either by selling it directly to consumers or by selling it to buyers (mead houses or retailers). Contracts between farmers and buyers (retailers, mead houses) or processors are scarce and largely oral. Only the private processing company Dimma employs written contracts to obtain honey from farmers or cooperatives. The obligation of the supplier (honey producer) includes the supply of a specified amount of honey with a specified quality and delivery date to Dimma. The contract also stipulates the obligations of Dimma including paying a fixed price per kilogram during the time of delivery and delivering honey at a specified place (producers place) by sending their own procurement experts. Dimma has signed contracts with marketing cooperatives listing the name of each member in the contract. The contract also stipulates the modern beehive, extractors, smokers and honey containers provided to the marketing cooperatives. The agreements also specify conditions to terminate the contract but any of the contracting party is required to inform ahead of time (1 month earlier).
Formal cooperative establishment in ethiopia dates back to 1960. Since then further expansion and declarations have been in place. Thre was a new proclamation by the Federal Democratic Republic of Ethiopia (FDRE) in 2002 and establish Federal Cooperative Agency to organize and promote cooperatives at national level. Different types of cooperatives are established in diffecent rural hillages (kebeles) throughout the nation: producer cooperatives, marketing cooperatives, multipurpose cooperatives, consumers' cooperatives (Bernard et al., 2008; Emana, 2009; Bernard and Alemayehu 2008).
With regard to cooperatives in Tigray, The survey conducted by the Agricultural Transformation Agency of Ethiopia has indicated that there were no cooperatives before 1991 (Bernard et al. 2008). Farmer cooperatives in the honey sector were launched once private beekeeping and honey processing company (Dimma) transferred its own apiary sites to selected farmers who were living closer to the apiary sites. These cooperatives are operating in the production and marketing of honey. Farmer cooperatives possess common apiary sites and individual beehives and obligate members to commit themselves to take care of apiary cites. They also have common processing technology such as honey extractors, masks and smokers that are provided by government or other development partners (e.g. ARDO, REST, and World Vision). The marketing cooperatives not only collect honey from farmers but provide different processing technology to honey producers. They also facilitate access to credit to acquire modern beehives for their members. These cooperatives also supply honey for the other processing companies (Wukiro Mar and Wolela Mar) that are operating at small-scale level.
Cooperatives established in Tigray are multipurpose cooperatives, marketing cooperatives, producer cooperatives and credit and saving cooperatives. Honey producers are memebrs of marketing cooperatives to supply honey to buyers specifically to Dimma beekeeping and honey processing. They also supplied honey for Wukiro Mar and Wolela Mar though they raise the issue of traceability problem while getting supply from marketing cooperatives. For this study, those members of honey marketing cooperatives are considered.
We apply a case study approach, using data from the Geba catchment in the Tigray region in northern Ethiopia. This area was chosen as a focus site for a large collaborative and interdisciplinary research project which this study is part of.
The situation concerning beehive ownership and honey production in the northern highlands of Ethiopia is similar to the rest of the country. Most rural households possess traditional and modern beehives and produce small amounts of honey for the market and for household consumption, next to a range of other farm and non-farm activities. The number of traditional and modern beehives in Tigray is estimated to be 229,629 (61,311 modern and transitional, 168,315 traditional) and total honey production 3,272 tons, constituting 5 % of the national production (CSA, 2013).
Large volumes of honey are produced from traditional beehives and traditional extraction systems. These traditional systems often fail to meet processors' quality requirements. Due to intensive intervention by the government and by development partners, a shift from traditional to modern beehives is ongoing. This modernization has resulted in increased honey production and increased market supply stimulating producers and government to establish marketing cooperatives to empower producers in the market. Honey producers are increasingly seeking for better and more secure market outlets through contracts and cooperatives. In addition, the problem of adulteration and poor harvesting practices makes it difficult for processors to source sufficient volumes of good quality honey, which drives them to contract with individual honey producers and marketing cooperatives and offer extension services as part of the contracts.
A household survey was organized in the case study area in the period April-May 2010. As the aim of the study is to evaluate the different coordination mechanisms in the honey supply chain, honey producers possessing modern beehives who are registered by the rural development office were purposively selected. These households are selected expecting that they offer surplus honey to the market as they exploit modern technology. In the first stage of the sampling design, four districts (woredas) were selected out of a total of 10 districts in the Geba catchment area. The districts with the largest beekeeping households and with actual and potential surplus honey production were selected. These districts were identified in consultation with the district livestock experts in the Rural Development Office (RDO).
The selected districts, and the sampled producers in these districts, are mentioned in Table 1. In a second stage of the sampling design, all the sub-districts (tabias), all households' possessing modern beehives registered in the Tabia rural development offices were selected. The offices often supply modern beehives, extraction technology, smokers, etc. to generate income for the household. It is assumed that rural households involved in this extension package are likely to be commercial beekeepers, supplying at least some produce to the market. In the third stage, households from a list of all households included in the small-scale beekeeping extension package were randomly selected. This list of households was provided by the district livestock experts in the government extension offices. In this way, a total of 412 honey producers in 8 sub-districts were selected. Data collection was administered using trained enumerators.
Table 1 Distribution of sample households
Coordination mechanisms and performance of honey producers
Coordination mechanisms
Honey producers in the case study area are involved in three different types of marketing coordination arrangements, including spot market transactions (81 % of sampled producers), contract arrangements (12.5 %) and marketing cooperative arrangements (6.5 %). Some contract producers also sell honey through spot market arrangements. Cooperatives usually restrict member farmers not to participate in other types of transactions. Side selling by members usually involves disciplinary actions such as cancellation of membership. Those who are expelled from membership are devoid of access to modern hives on creditwhich are provided through cooperatives.
Socioeconomic characteristics
In Table 2 we compare some general characteristics of contract producers, cooperative producers and other producers. The results show that apiculture is a male-dominated activity but that cooperatives involve a slightly higher share of female producers. Contracted producers are younger and better educated than producers in cooperatives or on the spot market. We find no difference in experience and in ownership of land and livestock between contract producers, cooperative producers and other producers. Cooperative producers are located furthest from the road but closest to Mekelle, the regional capital. Also contract producers are located further from a road than producers operating in sport markets.
Table 2 Socioeconomic characteristics of honey producers
Honey production, marketing and income
In Table 3 we compare the three different types of honey producers with respect to honey production and marketing. These figures indicate that contract producers possess a larger number of modern beehives, produce larger volumes of white honey, have a higher productivity per hive, sell a higher amount of honey in the market, and have higher incomes in general and from honey in particular in contrast to spot market producers. We find no differences in beehive possession, honey production, hive productivity and income between cooperative members and spot market suppliers.
Table 3 Production and marketing of honey for different producers
Table 4 Effect of contracts and cooperatives on honey producing farmers
Comparing the number of current modern beehives possession from what they had 5 years ago, the figures in Table 3 show that there has been an increase in the average number of modern beehives for all types of producers. Almost half of the farmers in the sample, 49 %, have at least one modern hive. This increase is partially the result of government and NGO interventions to supply modern hive technology, training and extension to enhance honey production and quality, as part of a poverty-reduction strategy. Different projects, e.g. ARDO (credit from Dedebit Credit and Saving Institution and other development partners), the Myzegzeg project, World Vision, the Catholic Church and the Ethiopian Orthodox Tewahido Church, provided modern beehives and technology to farmers and 35 % of honey producers in the sample received modern technology through this channel. The Dimma Honey Processing Company also provides beehives to honey producers and cooperative members committing to supply honey to the company; this is the case for 3 % of producers in the sample. Some producers bought modern beehives themselves or received them from other buyers.
Honey producers in the districts report the receipt of extension services to improve honey quality which include the provision of modern hives, training on honey extraction and quality standards, and the provision of equipment such as smokers and masks. Thirty percent of the honey producers operating in spot markets and 28.6 % of the cooperative members and 17 % of contract participants did not make further investment on buying modern hives and technology to improve quality. Twenty percent of the contract participants obtained credit and technology support from processors and buyers. A large part of the cooperative members and contract producers indicates that honey sales and incomes are increasing from year to year. However, nearly 31 % of the spot market producers say their honey sales go down.
Econometric approach
The descriptive statistics presented in the previous section indicates that honey producers who market their produce through contracts have more modern beehives, a higher total and per hive honey production, and a higher income in total and from beekeeping specifically. However, based on a simple comparison of averages across honey producers in different coordination channels, it is impossible to identify causality. To reveal whether the observed differences in performance between contract producers, cooperative producers and spot-market producers are attributable to the different coordination channels, a more profound econometric analysis is needed.
Three different methods are used to analyze the impact of contract and cooperative coordination in the honey supply chain on producers' performance. First, a simple regression model is used – referred to as regression on covariates. It is clear from the descriptive statistics in the previous sections, that there are important differences between contract, cooperative and spot-market employing honey producers in terms of observable characteristics. These differences indicate that participation in contracts and cooperatives is not randomly distributed over the population of honey producers, but influenced by households' physical, human and social capital endowments, and their access to markets and road infrastructure. To correct for the potential bias that may arise from this non-random selection into contracts and cooperatives, a large set of observable covariates is included as control variables in the estimation
$$ {Y}_i=\alpha +{\upgamma}_1{C}_{1i}+{\upgamma}_2{C}_{2i}+\beta {X}_i+{\varepsilon}_i $$
We look at five different outcome variables Y: (1) hive productivity (kg), (2) honey production (kg), (3) honey income (birr), (4) total household income (birr), and (5) per capita household income (birr) and these variables are log-specified in the model. The variables C1 and C2 represent the different coordination mechanism, contracts and cooperatives respectively. These are the main variables of interest and the coefficients γ1 and γ2 are referred to as the treatment effects of contracts and cooperatives respectively. The vector X includes a large set of observable covariates to correct for potential bias due to selection on observables: village dummy, distance to RDO, distance to asphalt road, land size, number of beehives, number of children, education, age, and household size. This model is estimated using Ordinary Least Squares (OLS) estimation.
The second estimation is based on estimated propensity scores – or a conditional probability to contract or to join cooperatives – and uses these as additional control variables in the regression model. This model is referred as regression on propensity scores. Adding the propensity score as an additional control variable in the regression further reduces the potential bias created by selection on observable characteristics (Imbens, 2004). Because there are two different treatments, contract and cooperatives, that are mutually exclusiveFootnote 1, a bivariate probit model is used to estimate the probability for each treatment, conditional on the set of covariates X (Lechner 1999, 2002). The model is specified as follows:
$$ {Y}_i=\alpha +{\upgamma}_1{C}_{1i}+{\upgamma}_2{C}_{2i}+{\mu}_1P{S}_{1i}+{\mu}_2P{S}_{2i}+\beta {X}_i+{\varepsilon}_i $$
$$ withP{S}_{1i}=p\left({C}_1=\frac{1}{X}\right) andP{S}_{2i}=p\left({C}_2=\frac{1}{X}\right) $$
Third, the effect of contracts and cooperatives on the performance of honey producers is estimated using a propensity score matching technique, which is referred to as matching on the propensity score. This method is widely applied in the agricultural and development economics literature (e.g., Maertens and Swinnen, 2009; Ito et al. 2012; Jena et al. 2012; Abebaw and Haile 2013; Egziabher et al. 2013) and has been referred to as the best option next to randomization and experimental design in solving selection bias (Khandker et al., 2010). As Khandher et al. (2010: 54) put it: "when we fail to randomize treatment, the next best option is to use an observational analogue to mimic randomization with matching and one can set up a counterfactual similar to the treatment group in terms of observed characteristics". Propensity score matching involves matching treated households with control households that are similar in terms of observable characteristics (Imbens and Angrist; 1995; Imbens, 2004; Caliendo and Sabine 2005). As matching directly on observable characteristics is difficult if the set of potentially relevant characteristics is large, matching on propensity scores has been proposed as a valid method (Rosenbaum and Rubin, 1983). All contract producers and all cooperative producers (the treated observations) in the sample are matched with one or several spot market producers (the control observations) who have similar propensity scores, with propensity scores as defined in equation (1). The effect of contracts and cooperatives on honey producers' performance can then be calculated as a weighted difference in outcome between treated observations and matched controls:
$$ AT{E}_1=\mathrm{E}\left({\mathrm{Y}}_1-{\mathrm{Y}}_0\right)=\frac{1}{N_1}{\displaystyle \sum_{i\in {N}_1}\left({Y}_{1i}-{Y}_0\right)\ for\ {C}_1=1} $$
where, ATE1 and ATE2 represent the average treatment effects from contracts and cooperatives respectively, N1 and N2 the number of households participating in contracts and cooperatives, Y1and Y 2 the outcomes for contract and cooperative farmers and Y0 of the outcome for the control group (spot market producers).
Two different matching procedures are used. Nearest neighbor matching, in which every treated household is matched to the control household with the closest propensity score. This is the most commonly applied matching algorithm in propensity score matching estimation (Ichino et al., 2008). It is complemented with a kernel matching technique, in which information from all control observations is used to compute the Average Treatment Effect (ATE) estimate (Caliendo and Sabine 2005). For kernel matching the biweight kernel type and the default bandwidth in STATA (0.06) are used. Matching is always done with replacement and only observations in the common support region – where the propensity score of the control units is not smaller than the minimum propensity score of the treated units and the propensity score of the treated units not larger than the maximum propensity score of the control units – are used in the analysis. As propensity score matching methods are sensitive to the exact specification and matching method, the use of different matching techniques serves as a robustness check.
Propensity score matching is based on two assumptions: conditional independence (CI) and common support (CS). The first assumption refers to potential outcomes being independent of treatment assignment, given a set of observable covariates X (Rosenbaum and Rubin, 1983; Dehejia and Wahba, 2002; Lechner 2002; Ichino et al. 2008):
$$ {\mathrm{Y}}_0,{\mathrm{Y}}_1,{\mathrm{Y}}_2\perp \mathrm{C}\left|\ \mathrm{X}\right. $$
The second assumption refers to sufficient overlap in the distribution of the propensity scores for treated and control observations (Rosenbaum and Rubin, 1983; Dehejia and Wahba, 2002; Lechner 2002; Ichino et al. 2008):
$$ 0\kern1em <\mathrm{P}\ \left(\mathrm{C}=1\left|\ \mathrm{X}\right.\right)<1 $$
These assumptions are addressed after the discussion of the results.
Impact of contracts and cooperatives on farm performance
The main results regarding the effect of the two treatment variables (contracts and cooperatives) on five performance indicators (hive productivity, honey production, honey income, household income, per capita income) from four alternative estimation techniques (regression on covariates, regression on propensity score, kernel matching and nearest neighbor matching) are given in Tables 4 and 5.
Table 5 Regression on covariates and regression on PS (HH income as dependent variable)
On the one hand, the econometric results confirm that participating in contracts results in significantly higher hive productivity, higher total honey production, and higher producer incomes. Taking the most conservative estimates, we find that contract production increases the productivity of modern beehives by 37 % and the total annual amount of production of honey with 76 %. In addition, income from honey production increases with 85 %, total household income with 28 % and per capita income with 31 % if honey is produced under contract. These are large and important effects, which show that contract farming and the technology transfers and reduced transaction costs that contracting entails, can be a tool for income growth in rural areas of developing countries. Our results show that the positive effects of contract farming on productivity and producer income that previous studies showed for high-value crops and export-oriented food chains (e.g. Key and McBride 2003; Maertens and Swinnen, 2009; Maertens et al., 2011; Miyata et al., 2009) also hold for lower-value produce and local food chains.
On the other hand, we do not find an effect of participating in cooperatives on hive productivity, honey production or household income. None of the estimated effects of cooperatives on hive productivity, honey production, honey income, total household income and per capita household income in the four different models are significant (Table 6). A possible explanation for the lack of an effect of cooperatives on farm performance is mismanagement in the cooperatives. The visited honey cooperatives in the study areas are found performing under capacity, losing their queen bees due to free riding (members not taking care of collective beehives) and space problems. Members are found not to invest their time in caring for the common apiary sites and some of the beehives are found with no bee colonies. Honey cooperatives emerge once Dimma initiated and transferred its apiary sites in 2007 to members nominated by the rural development offices. Members formed the cooperative to acquire modern beehives and other related technology relevant to honey production and harvesting. However, members reduce their commitment to take their own share once the cooperative is dissolved. Moreover, the fragile commitments from the members exacerbate the lower productivity of the beehives. As it was physically observed, honey cooperatives in the tabias Menkere and Hayelom are found underperforming losing the colonies due to lack of care from members. When cooperatives collect honey from their members, they also suffer from traceability problems resulting in partial or complete rejection of the honey offered to processors as it fails to meet standards. Lack of quality checking instruments also affects the success of cooperatives. The success of dairy cooperatives in the region has not been replicated in the honey producing and marketing cooperatives. Members in Atsibi and Ofla reduce their commitment to honey cooperatives and are waiting for the distribution of assets from the dissolution. Therefore, many of the members transfer the cooperatives' duties to the management committee and members fail to discharge the cooperative assignment prioritizing their own individual activity.
Table 6 Covariates used to estimate PS using the bivariate Probit Model
We can conclude that contracts offer better opportunities to honey producers than cooperatives. Contracts facilitate the acquisition of technology and inputs and result in better market conditions. They facilitate closer communication between producers and contractors (processors or retailers), and reduce transaction costs in multiple ways. While cooperatives also entail the potential to reduce transaction costs and result in better market conditions, in the honey sector in Tigray they are not successful in doing so, likely because of problems with management and incentives of producers.
In Table 5 the full regression results are given for the regression on covariates and the regression on propensity scores for total household income as dependent variable. The results indicate that apart from contract participation, other factors influence honey production and income as well. We find that the location of households matters. Households in the Ofla district have a significantly higher income than households in other districts. We find a negative effect of age but a positive effect of producer experience on household income. Further, labor endowments and productive assets determine household income. We find that a higher number of active household members, more livestock, and more beehives increase income of the households.
Estimating the propensity scores
The results of the bivariate probit model estimating the propensity scores are given in Table 6. These results indicate that the age of the household head, the size of the land and distance to an asphalt road influence the probability of producers to engage in contracting while household size, number of livestock units, number of traditional hives and distance to asphalt road influence the probability to engage in cooperatives.
Robustness and sensitivity
One of the important assumptions in propensity score matching is the overlap in the distribution of the estimated propensity scores for the treated and the control observations. The boxplot presented in Fig. 1 indicates the presence of sufficient overlap of the estimated propensity scores between the treated and the control observations. Some observations are outside the area of common support but these were dropped from the analysis.
Propensity scores of the treatment and control group. The first caption (a) is treated contract, control contract; the second caption (b) is treated cooperative, control cooperative
Related to this is the balance of observable characteristics between treated and matched control observations. As matching is done on the propensity scores rather than on all the covariates, one has to check whether the matching procedure is able to balance the distribution of the chosen covariates in both the treatment and the control group. The balancing test results in Table 7 indicate that significant differences in the covariates 'age of the household head', 'distance to asphalt road' and 'distance to RDO' between treated and controls disappear after matching. This indicates that matching results in more balance in characteristics between treated and controls, which leads to good estimates.
Table 7 Balancing properties of covariates in treated and control groups for kernel matching (Full Model)
Another important assumption is the Conditional Independence Assumption (CIA). This assumption cannot be directly tested since the information on the counterfactual is not available. However, Nannicini (2007)Footnote 2 and Ichino et al. (2008) proposed a method based on a simulated confounder to test sensitivity to failure of the CIA assumption. It involves the use of a simulated neutral confounder or a confounder that mimics the distribution of dummy covariates used in the computation of the propensity scores. We use a neutral confounder and a confounder calibrated to mimic the illiterate variable in the model. The sensitivity analysis result reveals qualitatively identical and quantitatively similar estimates of treatment effects, implying that the results are not sensitive to failure of the CIA assumption (Table 8).
Table 8 Sensitivity analysis for robustness of the CIA
A final sensitivity analysis includes a check of the appropriateness of the covariates used to estimate the propensity scores as the treatment effect estimate is sensitive to the chosen covariates. Two basic models were run to check the appropriateness of the chosen covariates. The first model estimates the treatment effect using all covariates identified to adjust the selection bias. The variables are stable, time invariant, fixed and measured before treatment (Caliendo and Sabine 2005). The second model is a restricted model consisting of covariates that are significant in determining the choice of contract or cooperatives from the full model. The two models yield qualitatively the same and quantitatively similar results supporting the robustness of the treatment effect estimate (Table 9).
Table 9 Sensitivity of ATE estimates under full different sets of covariates
This paper identified three basic marketing channels farmers employed to supply honey. The paper also identified an increased use of modern beehives across honey producers. Contracting honey producers are shown with a relatively large number of modern beehives and they get transformed fast. Input and technology supply is largely from ARDO but some buyers, processors, and other religious and development institutions also participate in the provision of modern hives and extracting technology to honey producers.
We indicated the positive production and economic gains honey producers obtain from contract engagement. Honey producers under the contract scheme produce more white honey fulfilling the demand of processors, buyers and consumers. Contracting results in higher production due to the better access it causes to technology and skill transfers. Moreover, better conditions contracts offer motivates honey producers to produce more to the market.
As the findings imply, contract farming is found offering improved incomes to the honey producers which complement the existing literature on contract farming. It however does not find any evidence in support of honey cooperatives to supplement household income. This may entail that the effectiveness of vertical coordination mechanisms is product specific.
It is inferred from the study that contracting offers resources and better market conditions and we suggest that facilitating conditions that favor contracting in rural Tigray may be considered to upgrade the honey supply chain. Strengthening enforcement and standardizing institutions to facilitate contracting in the region may be considered an option to improve the honey supply chain and the household income. Minimizing the act of farmers to side sell by offering flexible and market based agreements may also tighten the linkages of honey producers with contractors.
Though changes have been realized in the modern hive use among cooperative members, production and economic gains do not seem different from the situations of the spot market users. As supplemented by the discussions with cooperative leaders, members lack commitment to spend their time on the apiary site and there has been a tendency of free riding (leaving the work to others). Traceability problems also affect the revenue cooperatives could generate from what they made available in the market. Many of the honey producing cooperatives under the study sites are not properly functioning and they are in the process of reestablishment. Cooperative formation has been seen by members as a simple source of modern beehives and credit, and members' lower commitment to get their shares from dissolution.
The nature of the production system may also lend itself to the poor performance of cooperatives. Traditionally, beehives are placed within homes or backyards promoting individual commitment. However, cooperatives are given apiary sites demanding frequent visit and follow up to which many of the members fail to commit. In addition, lack of space and pesticide use around the apiary sites were reported to be the reasons impeding hive productivity. In sum, contracting is found to be instrumental for improving honey production, sales and income. However, care must be taken in interpreting the result as contract and cooperative participants are small in number. Conducting the survey at larger scale may be relevant to develop the complete picture on the contributions of contracts to honey production and producers' welfare in Ethiopia. As such types of studies are scarce, it is difficult to have a benchmark to compare the marginal yield and the welfare effect of contract participation. It is then believed that it may serve as a good reference for similar studies in the future.
This is the case because cooperative members are obliged to sell the entire marketable output to the cooperative and hence cannot engage in other marketing channels.
For the reasoning and the applications in STATA, see Nannicini (2007).
Abebaw D, Haile GM (2013) The impact of Cooperatives on agricultural technology adoption. Food Policy 38:82–91
Abebe W, Ranjitha P (2011) Beekeeping sub sector challenges and constraints in Atsbi Wemberta District of eastern zone, Tigray Region, Ethiopia. J Agric Ext Rural Dev 3(1):8–12
Bernard T, Alemayehu T (2008) Returns to scope? Smallholders' commercialization through multipurpose cooperatives in Ethiopia. J Afr Econ 0(0):1–25
Bernard T, Alemayehu T, Eleni GM (2008) Impact of cooperatives on smallholders' commercialization behaviour: evidence from Ethiopia. Agric Econ 39:147–161
Bijman J, Hendrikse G (2003) Co-operatives in chains: institutional restructuring in the Dutch fruit and vegetable industry. Chain and network science 3(2):95–107
Bijman J, Hu D (2011) The rise of new farmer cooperatives in China: evidence from Hubei Province. J Rural Coop 39(2):99–113
Blandon J, Henson S, Cranfield J (2009) Small-scale farmer participation in new agri-food supply chains: case of supermarket supply chains for fruit and vegetables in Honduras. J Int Dev 21:971–984
Bolwig S, Gibbon P, Jones S (2010) The economics of smallholder organic contract farming in Tropical Africa. World Dev 37(6):1094–1104
Caliendo M, Sabine K (2005) Some practical guidance for the implementation of propensity score matching. IZA Discussion Paper No.1588
Dehejia RH, Wahba S (2002) Propensity score-matching methods for non-experimental causal studies. Rev Econ Stat 84:151–161
Dorward AR, Kydd J, Poulton C (2006) Traditional Domestic Markets and Marketing Systems for Agricultural Products Centre for Development and Poverty Reduction; Centre for Environmental Policy, Imperial College London, London p 43
Dorward AR, Kydd J, Poulton C (2007) Coordination risk and cost impacts on economic development in poor rural areas. School of Oriental and African Studies, University of London, London p 37
Dries L, Germenji E, Noev N, Swinnen JFM (2009) Farmer, vertical coordination, and restructuring of dairy supply chains in Central and Eastern Europe. World Dev 37(11):1742–1758
Egziabher KG, Mathijs E, Deckers J, Gebrehiwot K, Bauer H, Maertens M (2013) The economic impact of a new rural extension approach in northern Ethiopia, Working Paper 2013/2, Bioeconomics Working Paper Series. KUL, Belgium
Emana B (2009) Cooperatives: a path to economic and social empowerment in Ethiopia. Cooperatives facility for Africa. ILO, Dar es Salam, p 44
FAO (2015) FAOSTAT http://faostat3.fao.org [accessed in 5 June 2015].
Francesconi GN, Nico H (2010) Ethiopian agricultural cooperatives in an Era of global commedity exchange: does organizational form matter? J Afr Econ 20(1):153–177
Gabre-Madhin EZ (2001) Market Institutions, Transaction Costs, and Social Capital in the Ethiopian Grain Market. Research Report 124. IFPRI, Washington D.C
Gezahegn A, Nebil K, Samru M (2006) Strategic options for quality improvement of Ethiopian beeswax exports. Paper prepared for the stakeholders of the honey and beeswax value chain coordination group. Netherlands Development Organization, Addis Ababa
Gillespie JM, Eidman VR (1998) The effect of risk and autonomy on independent hog producers' contracting decisions. J Agric Appl Econ 30:175–88
Hendrikse G, Bijman J (2002) Ownership structures in agrifood chains: the marketing cooperative. Am J Agric Econ 84(1):104–119
Ichino A, Mealli F, Nannicini T (2008) From temporary help jobs to permanent employment: what can we learn from matching estimators and their sensitivity? J Appl Econ 23:305–327
Imbens G (2004) Nonparametric estimation of average treatment effects under exogeneity: a review. Rev Econ Stat 96(1):4–29
Imbens G, Angrist J (1995) Two-stage least square estimation of average causal effects in models with variable treatment intensity. J Am Stat Assoc 90(430):431–442
Ito J, Bao Z, Su Q (2012) Distributional effects of agricultural cooperatives in China: Exclusion of smallholders and potential gains on participation. Food Policy 37:700–709
Jayne TS, Mather D, Elliot M (2010) Principal challenges confronting smallholder agriculture in Sub-Saharan Africa. World Dev 38(10):1384–1398
Jena PR, Chichaibelu BB, Stellmacher T, Grote U (2012) The Impact of coffee certification on smallholder producers' livelihoods: a case study from the Jimma zone, Ethiopia. Agric Econ 43:329–440
Key N (2004) Agricultural contracting and the scale of production. Agric Resour Econ Rev 3(2):255–271
Key N, McBride W (2003) Production contracts and productivity in the U.S. hog sector. Am J Agric Econ 85(1):121–133
Key N, Runsten D (1999) Contract farming, smallholders, and rural development in Latin America: the organization of agro-processing firms and the scale of out grower production. World Dev 27(2):381–401
Khandker R, Gayatri B, Hussain A (2010) Handbook on impact evaluation: quantitative methods and practices. The World Bank, Washington D.C
Lechner M (1999) Identification and estimation of causal effects of multiple treatments under the conditional independence assumption. IZA DP No. 91
Lechner M (2002) Program heterogeneity and propensity score matching: an application to the evaluation of active labor market policies. Rev Econ Stat 84(2):205–220
Legesse GY (2014). Review of progress in Ethiopian honey production and marketing. livestock research for rural development, volume 26, article#14. http://www.lrrd.org/lrrd26/1/lege26014.htm.
Maertens M, Swinnen JFM (2009) Trade, standards and poverty: evidence from Senegal. World Dev 37(1):161–178
Maertens M, Colen L, Swinnen JFM (2011) Globalization and poverty in Senegal. Eur Rev Agric Econ 38(1):31–54
Masakure O, Henson S (2005) Why do small-scale producers choose to produce under contract? Lessons from nontraditional vegetable exports from Zimbabwe. World Dev 4(4):1–13
Melaku G, Shifa B, Azege T, Negatu A, Lulseged B (2008) Approaches, methods and processes for innovative apiculture development: experiences from Ada'a-Liben Woreda, Oromia Regional State, Ethiopia. Improving Productivity and Market Success (IPMS) of Ethiopian Farmers Project Working Paper 8. ILRI, Nairobi
Minten B, Randrianarison L, Swinnen JFM (2007) Global Supply Chains, Poverty and Environment: Evidence from Madagascar. In: Swinnen JFM (ed) Global Supply chains, standards and the poor. CABI, UK
Miyata S, Nicholas M, Hu D (2009) Impact of contract farming on income: linking small farmers, packers, and supermarkets in China. World Dev 37(11):1781–1790
Nannicini T (2007) A simulation-based sensitivity analysis for matching estimators. Stata J 7(3):305–327
Nwankwo U, Kurt M, Peters J, Wolfgang B (2009) Can cooperative membership and participation affect adoption decisions? Issues for sustainable biotechnology dissemination. AgBioForum 12(3&4):437–451
Paulos D (2012) Ethiopian Honey: Accessing international markets with inclusive business and sector development. Seas of Change, SNV Ethiopia, The Hague, p 7
Rosenbaum PR, Rubin DB (1983) The central role of propensity score in observational studies for causal effects. Biometrika 70:41–55
Schipmann C, Qaim M (2010) Spillovers from modern supply chains to traditional markets: product innovation and adoption by smallholders. Agric Econ 41:361–371
Simmons P, Winters P, Patrick I (2005) An analysis of contract farming in East Java, Bali, and Lombok, Indonesia. Agric Econ 33:513–525
Singh S (2002) Contracting out solutions: political economy of contract farming in the Indian Punjab. World Dev 30(9):1621–1638
Staal SJ, Delgado C, Nicholson C (1997) Smallholder dairying under transactions cost in East Africa. World Dev 25(5):779–794
CSA (Central Statistical Agency) (2013) Livestock survey report. Central statistical agency, Addis Ababa, Ethiopia
Swinnen JFM, Maertens M (2007) Globalization, privatization and vertical coordination in food value chains in developing and transition countries. Agric Econ 37:89–102
Takane T (2004) Smallholders and nontraditional exports under economic liberalization: the case of pineapples in Ghana. Afr Stud Monogr 25(1):29–43
Verhofstadt E, Maertens M (2014) Can Agricultural cooperatives reduce poverty? Heterogeneous Impact of cooperative membership on farmers' welfare in Rwanda. Appl Econ Perspect Policy 37(1):86–106
Weatherspoon DD, Reardon T (2003) The rise of supermarkets in Africa. Dev Policy Rev 21(3):333–355
Williamson OE (1979) Transaction-cost economics: the governance of contractual relations. J Law Econ 22(2):233–261
Department of Earth and Environmental Sciences, Katholieke Universiteit Leuven, Celestijnenlaan 200 E, 3001, Leuven, Belgium
Miet Maertens
, Jozef Deckers
& Erik Mathijs
SARChI Chair in Social Policy, University of South Africa, Nana Sita street 263, Pretoria, 003, South Africa
Abebe Ejigu Alemu
Department of Management, CBE, Mekelle University, Mekelle, Ethiopia
WildCRU - The Recanati-Kaplan Centre, Zoology, University of Oxford, Ministry of Education, room 317, PO Box 80522, Addis Abeba, Ethiopia
Hans Bauer
Search for Abebe Ejigu Alemu in:
Search for Miet Maertens in:
Search for Jozef Deckers in:
Search for Hans Bauer in:
Search for Erik Mathijs in:
Correspondence to Erik Mathijs.
We declare that we do not have competing interests.
All authors designed the research. AEA collected and analysed the data. AEA, MM and EM interpreted the results and wrote the article. All authors read and approved the final manuscript.
Supply chain coordination
Honey production
JEL code


A police chase from Wauseon to Morenci last Wednesday left officers without the fleeing driver and puzzled over a hit-and-run incident.
A vehicle was stopped in Wauseon for a registration check at 4:40 p.m. Jan 2, but after the police officer made verbal contact, the driver sped off.
The Wauseon officer and a Fulton County Sheriff's Department officer both pursued the vehicle and eventually ended up in Morenci, where officer Don Thompson became involved in the chase.
The fleeing driver sped along several Morenci residential streets, but officers were unable to block his travel. He struck a vehicle at the intersection of Elm and East Street South as he was heading south out of town and back into Ohio.
When the Wauseon officer realized the woman driving the other vehicle was not injured, he continued with the pursuit.
The fleeing driver apparently turned off State Route 108 onto a county road and escaped. The Wauseon officer then notified Morenci about the crash, but Officer Thompson was unable to locate the victim. So far, the accident has not been reported.
The fleeing driver was recognized by the Wauseon officer as a 27-year-old male from Fayette and charges are pending.
Morenci police are seeking information about the accident at Elm Street for possible prosecution of the Fayette driver. Morenci police chief Larry Weeks said the car received minor damage.
Anyone with information should call the Morenci Police Department at 458-7104.


The Creative Doll: Time Flies!
I moved two years ago, well a little more than that, and I am still amazed at the time it has taken me to downsize. I am still working at it! And I thought it would take me just 6 WEEKS!! I soldier on. I am in my umpteenth iteration of furniture and where it should go, and selling things an replacing things, but we finally believe we have a plan. We thought so before but that is my story and I am sticking to it. Both of us have lost our parents. My mother-in-law passed away in April. We keep adjusting to our new normal, as does everyone. But we also count our blessings and hope that all of you are able to keep your dolling as a part of joy and that it gets you through your tough spots.
It has been since January posting on this blog. And believe it or not, I have done a few things, with a list of a LOT more. I want to do better posting on the blog. (Science and technology have gotten in the way and this is a new try in a new technology for me to upload, so we'll see how it works. If you are reading this, it does, and now I need to perfect it.) All this chasing technology and learning, probably good for my mind, but not my wallet. I would rather be buying fabric.
The last Convention I went to for United Federation of Doll Clubs was in Washington D.C. While looking at the display, I and many others, went gaga over the Chiffonette doll and her wardrobe. I attended the luncheon of Sylvia McNeil, and received the book of her doll, it is thought it be a Huret, and have longed to make those child dresses of the 1860's. They are quite simple in look if not in execution. And one can get many looks from one pattern, by changing trims and changing fabrics. Susan Sirkis, long my doll dressing idol, did a pattern CD of the Lilas, and I used her patterns with some adjustments to use for my dolls. So, with so much inspiration form the Chiffonette display and Susan's patterns I went to work on my little 6" Rohmer reproduction. The porcelain for my doll was created for me by my friend Kate, and her body was from Create a Doll. A beautiful tiny leather body. She is 6" tall. I haven't named her.
I decided to gather her and her wardrobe together in a shadow box from Michael's. I hope you will enjoy her, and this little interlude will give me a little more time to do more posts to share with you. Many projects planned for the summer.
To all the Mothers out there, Happy Mother's Day and I hope all you do is appreciated.


We recently booked a cruise through [NAME OF TOUR OPERATOR] Uk. When we received our statement/Itinery. We noticed we had 3 more flights than had been mentioned in the original booking. No one told us and I am a poor flyer so I would have not chosen this particular cruise if I had known about this. Can they do this after the booking has been made and do we have to go ahead with the cruise?


We are sorry that the Cat 980F 8CJ01110 is sold out. If you are interested in other Wheel Loaders products, let's find out more Here. or go to the page of Caterpillar Heavy Equipment to see more heavy equipment from the producer.
Machine ran and operated at the time of inspection. Articulation P&B is weak. Cat 9U1287 bucket good edges, bottom of bucket has holes in it. Hole in bottom of muffler, Trans filter base is leaking, Trans is low on oil, hose on left side of transmission is leaking badly, right mirror bracket is bent, brake cans are leaking, tilt z link p&b are loose. Good tires.
Have a question on this Cat 980F?


Many of the original land entries in Tennessee were Military Bounty Land Claims. And while they were supposed to apply to the military land district only–along the Cumberland River in Middle Tennessee–claims on the land extended across eastern, middle, and into western Tennessee.
Availability of these extensive bounty lands led your ancestors to claim military service–even if they did not serve; or, even if they served on the wrong side; or, even if they served in the wrong state! Even if, your ancestor was originally from Virginia, if he claims military service in North Carolina, for Tennessee lands, you can find him. By using the claim number with related document numbers, you can track your ancestor from Tennessee back to his home county in North Carolina.
What a great time it is to be searching for those difficult-to-find ancestors in Tennessee!
1784 Extension Act, persons who served in the militia or died during settlement of Davidson County granted 640 acres. 152 persons are named in the law itself.


text:
Q: How to mock a generic parameter for a unit test in Java? I have a function signature I'd like to mock of an External Service.
public <T> void save(T item, AnotherClass anotherClassObject);

Given this function signature, and class name IGenericService how could one mock it with PowerMock?
Or Mockito?
For this generic, I'm using: Class Theodore for the T in T item. For example, I tried using:
doNothing().when(iGenericServiceMock.save(any(Theodore.class),
                    any(AnotherClass.class));

IntelliJ cranks this:
save(T, AnotherClass) cannot be applied to
(org.Hamcrest.Matcher<Theodore>, org.Hamcrest.Matcher<AnotherClass>)

And it cites the following reason:
reason: No instance(s) of type variable T exist
so that Matcher<T> conforms to AnotherClass

First, the issue ought to solve if the generics argument is handled properly. What are some things one could do in such situations?
UPDATE: As ETO shared:
doNothing().when(mockedObject).methodToMock(argMatcher);

shares the same fate.

A: You are passing wrong parameters to when. It may be a bit confusing, but there are two different usages of when method (actually those are two different methods):

*

*when(mockedObject.methodYouWantToMock(expectedParameter, orYourMatcher)).thenReturn(objectToReturn);

*doReturn(objectToReturn).when(mockedObject).methodYouWantToMock(expectedParameter, orYourMatcher);

Note: pay attention to input parameters of when method in both cases.
In your particular case you could do something like this:
doReturn(null).when(iGenericServiceMock).save(any(Theodore.class), any(AnotherClass.class));

This will fix your compilation issues. However the test will fail at runtime with org.mockito.exceptions.misusing.CannotStubVoidMethodWithReturnValue because you are trying to return something from a void method (null is not void). What you should do is :
doNothing().when(iGenericServiceMock).save(any(Theodore.class), any(AnotherClass.class));

Later you can check the interactions with your mock using verify method.
UPDATE:
Check your imports. You should use org.mockito.Matchers.any instead of org.hamcrest.Matchers.any.

A: Try to use the Mockito's ArgumentMatcher. Also in when put only the mock's reference:
doReturn(null).when(iGenericServiceMock).save(
    ArgumentMatchers.<Theodore>any(), ArgumentMatchers.any(AnotherClass.class));

A: Great and swift answers! I finally got it to smooth over with the following code:
doNothing().when(iGenericServiceMock).save(Mockito.any(), Mockito.any());

it wasn't until I prepended Mockito to the any method that Intellij became joyful about it again.

redpajama_set_name: RedPajamaStackExchange


text:
Øystein Øysteinsson, apodado el doncel (en nórdico antiguo, Eysteinn Meyla; en noruego, Øystein Møyla) (1152 - fallecido en Re, Noruega, en 1177). Fue un pretendiente al trono noruego, electo en 1176 como rey rival en oposición a Magnus V, durante el período de la guerra civil noruega.

Øystein era un hijo ilegítimo del rey Øystein II. Formó parte de la facción de los birkebeiner, que se levantaron contra Magnus V y el regente Erling Skakke.

En 1176 llegó a Nidaros, ciudad de la que se apoderó, junto con la región de Trøndelag. Ahí fue nombrado rey. Reunió un ejército de 2,400 hombres y partió hacia el sur, a través de las montañas, pero su ejército fue interceptado por Magnus V en Re, donde Øystein murió en batalla en el año de 1177.

Recibió el nombre de el doncel, por su aspecto juvenil. Aunque fue nombrado rey, su nombre no ha sido incluido en la lista oficial de los monarcas noruegos.

Véase también
 Guerras Civiles Noruegas

Referencias

Enlaces externos
 Øystein Øysteinsson Møyla – utdypning (Store norske leksikon)

Nobles de Noruega del siglo XII
Guerras Civiles Noruegas

redpajama_set_name: RedPajamaWikipedia


text:
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

#include "arrow/ipc/feather.h"

#include <algorithm>
#include <cstdint>
#include <cstring>
#include <memory>
#include <sstream>  // IWYU pragma: keep
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

#include <flatbuffers/flatbuffers.h>

#include "arrow/array.h"
#include "arrow/buffer.h"
#include "arrow/chunked_array.h"
#include "arrow/io/interfaces.h"
#include "arrow/ipc/metadata_internal.h"
#include "arrow/ipc/options.h"
#include "arrow/ipc/reader.h"
#include "arrow/ipc/util.h"
#include "arrow/ipc/writer.h"
#include "arrow/result.h"
#include "arrow/status.h"
#include "arrow/table.h"
#include "arrow/type.h"
#include "arrow/type_traits.h"
#include "arrow/util/bit_util.h"
#include "arrow/util/checked_cast.h"
#include "arrow/util/logging.h"
#include "arrow/util/make_unique.h"
#include "arrow/visitor_inline.h"

#include "generated/feather_generated.h"

namespace arrow {

using internal::checked_cast;
using internal::make_unique;

class ExtensionType;

namespace ipc {
namespace feather {

namespace {

using FBB = flatbuffers::FlatBufferBuilder;

constexpr const char* kFeatherV1MagicBytes = "FEA1";
constexpr const int kFeatherDefaultAlignment = 8;
const uint8_t kPaddingBytes[kFeatherDefaultAlignment] = {0};

inline int64_t PaddedLength(int64_t nbytes) {
  static const int64_t alignment = kFeatherDefaultAlignment;
  return ((nbytes + alignment - 1) / alignment) * alignment;
}

Status WritePaddedWithOffset(io::OutputStream* stream, const uint8_t* data,
                             int64_t bit_offset, const int64_t length,
                             int64_t* bytes_written) {
  data = data + bit_offset / 8;
  uint8_t bit_shift = static_cast<uint8_t>(bit_offset % 8);
  if (bit_offset == 0) {
    RETURN_NOT_OK(stream->Write(data, length));
  } else {
    constexpr int64_t buffersize = 256;
    uint8_t buffer[buffersize];
    const uint8_t lshift = static_cast<uint8_t>(8 - bit_shift);
    const uint8_t* buffer_end = buffer + buffersize;
    uint8_t* buffer_it = buffer;

    for (const uint8_t* end = data + length; data != end;) {
      uint8_t r = static_cast<uint8_t>(*data++ >> bit_shift);
      uint8_t l = static_cast<uint8_t>(*data << lshift);
      uint8_t value = l | r;
      *buffer_it++ = value;
      if (buffer_it == buffer_end) {
        RETURN_NOT_OK(stream->Write(buffer, buffersize));
        buffer_it = buffer;
      }
    }
    if (buffer_it != buffer) {
      RETURN_NOT_OK(stream->Write(buffer, buffer_it - buffer));
    }
  }

  int64_t remainder = PaddedLength(length) - length;
  if (remainder != 0) {
    RETURN_NOT_OK(stream->Write(kPaddingBytes, remainder));
  }
  *bytes_written = length + remainder;
  return Status::OK();
}

Status WritePadded(io::OutputStream* stream, const uint8_t* data, int64_t length,
                   int64_t* bytes_written) {
  return WritePaddedWithOffset(stream, data, /*bit_offset=*/0, length, bytes_written);
}

struct ColumnType {
  enum type { PRIMITIVE, CATEGORY, TIMESTAMP, DATE, TIME };
};

inline TimeUnit::type FromFlatbufferEnum(fbs::TimeUnit unit) {
  return static_cast<TimeUnit::type>(static_cast<int>(unit));
}

/// For compatibility, we need to write any data sometimes just to keep producing
/// files that can be read with an older reader.
Status WritePaddedBlank(io::OutputStream* stream, int64_t length,
                        int64_t* bytes_written) {
  const uint8_t null = 0;
  for (int64_t i = 0; i < length; i++) {
    RETURN_NOT_OK(stream->Write(&null, 1));
  }
  int64_t remainder = PaddedLength(length) - length;
  if (remainder != 0) {
    RETURN_NOT_OK(stream->Write(kPaddingBytes, remainder));
  }
  *bytes_written = length + remainder;
  return Status::OK();
}

// ----------------------------------------------------------------------
// ReaderV1

class ReaderV1 : public Reader {
 public:
  Status Open(const std::shared_ptr<io::RandomAccessFile>& source) {
    source_ = source;

    ARROW_ASSIGN_OR_RAISE(int64_t size, source->GetSize());
    int magic_size = static_cast<int>(strlen(kFeatherV1MagicBytes));
    int footer_size = magic_size + static_cast<int>(sizeof(uint32_t));

    // Now get the footer and verify
    ARROW_ASSIGN_OR_RAISE(auto buffer, source->ReadAt(size - footer_size, footer_size));

    if (memcmp(buffer->data() + sizeof(uint32_t), kFeatherV1MagicBytes, magic_size)) {
      return Status::Invalid("Feather file footer incomplete");
    }

    uint32_t metadata_length = *reinterpret_cast<const uint32_t*>(buffer->data());
    if (size < magic_size + footer_size + metadata_length) {
      return Status::Invalid("File is smaller than indicated metadata size");
    }
    ARROW_ASSIGN_OR_RAISE(
        metadata_buffer_,
        source->ReadAt(size - footer_size - metadata_length, metadata_length));

    metadata_ = fbs::GetCTable(metadata_buffer_->data());
    return ReadSchema();
  }

  Status ReadSchema() {
    std::vector<std::shared_ptr<Field>> fields;
    for (int i = 0; i < static_cast<int>(metadata_->columns()->size()); ++i) {
      const fbs::Column* col = metadata_->columns()->Get(i);
      std::shared_ptr<DataType> type;
      RETURN_NOT_OK(
          GetDataType(col->values(), col->metadata_type(), col->metadata(), &type));
      fields.push_back(::arrow::field(col->name()->str(), type));
    }
    schema_ = ::arrow::schema(std::move(fields));
    return Status::OK();
  }

  Status GetDataType(const fbs::PrimitiveArray* values, fbs::TypeMetadata metadata_type,
                     const void* metadata, std::shared_ptr<DataType>* out) {
#define PRIMITIVE_CASE(CAP_TYPE, FACTORY_FUNC) \
  case fbs::Type::CAP_TYPE:                    \
    *out = FACTORY_FUNC();                     \
    break;

    switch (metadata_type) {
      case fbs::TypeMetadata::CategoryMetadata: {
        auto meta = static_cast<const fbs::CategoryMetadata*>(metadata);

        std::shared_ptr<DataType> index_type, dict_type;
        RETURN_NOT_OK(GetDataType(values, fbs::TypeMetadata::NONE, nullptr, &index_type));
        RETURN_NOT_OK(
            GetDataType(meta->levels(), fbs::TypeMetadata::NONE, nullptr, &dict_type));
        *out = dictionary(index_type, dict_type, meta->ordered());
        break;
      }
      case fbs::TypeMetadata::TimestampMetadata: {
        auto meta = static_cast<const fbs::TimestampMetadata*>(metadata);
        TimeUnit::type unit = FromFlatbufferEnum(meta->unit());
        std::string tz;
        // flatbuffer non-null
        if (meta->timezone() != 0) {
          tz = meta->timezone()->str();
        } else {
          tz = "";
        }
        *out = timestamp(unit, tz);
      } break;
      case fbs::TypeMetadata::DateMetadata:
        *out = date32();
        break;
      case fbs::TypeMetadata::TimeMetadata: {
        auto meta = static_cast<const fbs::TimeMetadata*>(metadata);
        *out = time32(FromFlatbufferEnum(meta->unit()));
      } break;
      default:
        switch (values->type()) {
          PRIMITIVE_CASE(BOOL, boolean);
          PRIMITIVE_CASE(INT8, int8);
          PRIMITIVE_CASE(INT16, int16);
          PRIMITIVE_CASE(INT32, int32);
          PRIMITIVE_CASE(INT64, int64);
          PRIMITIVE_CASE(UINT8, uint8);
          PRIMITIVE_CASE(UINT16, uint16);
          PRIMITIVE_CASE(UINT32, uint32);
          PRIMITIVE_CASE(UINT64, uint64);
          PRIMITIVE_CASE(FLOAT, float32);
          PRIMITIVE_CASE(DOUBLE, float64);
          PRIMITIVE_CASE(UTF8, utf8);
          PRIMITIVE_CASE(BINARY, binary);
          PRIMITIVE_CASE(LARGE_UTF8, large_utf8);
          PRIMITIVE_CASE(LARGE_BINARY, large_binary);
          default:
            return Status::Invalid("Unrecognized type");
        }
        break;
    }

#undef PRIMITIVE_CASE

    return Status::OK();
  }

  int64_t GetOutputLength(int64_t nbytes) {
    // XXX: Hack for Feather 0.3.0 for backwards compatibility with old files
    // Size in-file of written byte buffer
    if (version() < 2) {
      // Feather files < 0.3.0
      return nbytes;
    } else {
      return PaddedLength(nbytes);
    }
  }

  // Retrieve a primitive array from the data source
  //
  // @returns: a Buffer instance, the precise type will depend on the kind of
  // input data source (which may or may not have memory-map like semantics)
  Status LoadValues(std::shared_ptr<DataType> type, const fbs::PrimitiveArray* meta,
                    fbs::TypeMetadata metadata_type, const void* metadata,
                    std::shared_ptr<ArrayData>* out) {
    std::vector<std::shared_ptr<Buffer>> buffers;

    // Buffer data from the source (may or may not perform a copy depending on
    // input source)
    ARROW_ASSIGN_OR_RAISE(auto buffer,
                          source_->ReadAt(meta->offset(), meta->total_bytes()));

    int64_t offset = 0;

    if (type->id() == Type::DICTIONARY) {
      // Load the index type values
      type = checked_cast<const DictionaryType&>(*type).index_type();
    }

    // If there are nulls, the null bitmask is first
    if (meta->null_count() > 0) {
      int64_t null_bitmap_size = GetOutputLength(BitUtil::BytesForBits(meta->length()));
      buffers.push_back(SliceBuffer(buffer, offset, null_bitmap_size));
      offset += null_bitmap_size;
    } else {
      buffers.push_back(nullptr);
    }

    if (is_binary_like(type->id())) {
      int64_t offsets_size = GetOutputLength((meta->length() + 1) * sizeof(int32_t));
      buffers.push_back(SliceBuffer(buffer, offset, offsets_size));
      offset += offsets_size;
    } else if (is_large_binary_like(type->id())) {
      int64_t offsets_size = GetOutputLength((meta->length() + 1) * sizeof(int64_t));
      buffers.push_back(SliceBuffer(buffer, offset, offsets_size));
      offset += offsets_size;
    }

    buffers.push_back(SliceBuffer(buffer, offset, buffer->size() - offset));

    *out = ArrayData::Make(type, meta->length(), std::move(buffers), meta->null_count());
    return Status::OK();
  }

  int version() const override { return metadata_->version(); }
  int64_t num_rows() const { return metadata_->num_rows(); }

  std::shared_ptr<Schema> schema() const override { return schema_; }

  Status GetDictionary(int field_index, std::shared_ptr<ArrayData>* out) {
    const fbs::Column* col_meta = metadata_->columns()->Get(field_index);
    auto dict_meta = col_meta->metadata_as<fbs::CategoryMetadata>();
    const auto& dict_type =
        checked_cast<const DictionaryType&>(*schema_->field(field_index)->type());

    return LoadValues(dict_type.value_type(), dict_meta->levels(),
                      fbs::TypeMetadata::NONE, nullptr, out);
  }

  Status GetColumn(int field_index, std::shared_ptr<ChunkedArray>* out) {
    const fbs::Column* col_meta = metadata_->columns()->Get(field_index);
    std::shared_ptr<ArrayData> data;

    auto type = schema_->field(field_index)->type();
    RETURN_NOT_OK(LoadValues(type, col_meta->values(), col_meta->metadata_type(),
                             col_meta->metadata(), &data));

    if (type->id() == Type::DICTIONARY) {
      RETURN_NOT_OK(GetDictionary(field_index, &data->dictionary));
      data->type = type;
    }
    *out = std::make_shared<ChunkedArray>(MakeArray(data));
    return Status::OK();
  }

  Status Read(std::shared_ptr<Table>* out) override {
    std::vector<std::shared_ptr<ChunkedArray>> columns;
    for (int i = 0; i < static_cast<int>(metadata_->columns()->size()); ++i) {
      columns.emplace_back();
      RETURN_NOT_OK(GetColumn(i, &columns.back()));
    }
    *out = Table::Make(this->schema(), std::move(columns), this->num_rows());
    return Status::OK();
  }

  Status Read(const std::vector<int>& indices, std::shared_ptr<Table>* out) override {
    std::vector<std::shared_ptr<Field>> fields;
    std::vector<std::shared_ptr<ChunkedArray>> columns;

    auto my_schema = this->schema();
    for (auto field_index : indices) {
      if (field_index < 0 || field_index >= my_schema->num_fields()) {
        return Status::Invalid("Field index ", field_index, " is out of bounds");
      }
      columns.emplace_back();
      RETURN_NOT_OK(GetColumn(field_index, &columns.back()));
      fields.push_back(my_schema->field(field_index));
    }
    *out = Table::Make(::arrow::schema(std::move(fields)), std::move(columns),
                       this->num_rows());
    return Status::OK();
  }

  Status Read(const std::vector<std::string>& names,
              std::shared_ptr<Table>* out) override {
    std::vector<std::shared_ptr<Field>> fields;
    std::vector<std::shared_ptr<ChunkedArray>> columns;

    std::shared_ptr<Schema> sch = this->schema();
    for (auto name : names) {
      int field_index = sch->GetFieldIndex(name);
      if (field_index == -1) {
        return Status::Invalid("Field named ", name, " is not found");
      }
      columns.emplace_back();
      RETURN_NOT_OK(GetColumn(field_index, &columns.back()));
      fields.push_back(sch->field(field_index));
    }
    *out = Table::Make(::arrow::schema(std::move(fields)), std::move(columns),
                       this->num_rows());
    return Status::OK();
  }

 private:
  std::shared_ptr<io::RandomAccessFile> source_;
  std::shared_ptr<Buffer> metadata_buffer_;
  const fbs::CTable* metadata_;
  std::shared_ptr<Schema> schema_;
};

// ----------------------------------------------------------------------
// WriterV1

struct ArrayMetadata {
  fbs::Type type;
  int64_t offset;
  int64_t length;
  int64_t null_count;
  int64_t total_bytes;
};

#define TO_FLATBUFFER_CASE(TYPE) \
  case Type::TYPE:               \
    return fbs::Type::TYPE;

Result<fbs::Type> ToFlatbufferType(const DataType& type) {
  switch (type.id()) {
    TO_FLATBUFFER_CASE(BOOL);
    TO_FLATBUFFER_CASE(INT8);
    TO_FLATBUFFER_CASE(INT16);
    TO_FLATBUFFER_CASE(INT32);
    TO_FLATBUFFER_CASE(INT64);
    TO_FLATBUFFER_CASE(UINT8);
    TO_FLATBUFFER_CASE(UINT16);
    TO_FLATBUFFER_CASE(UINT32);
    TO_FLATBUFFER_CASE(UINT64);
    TO_FLATBUFFER_CASE(FLOAT);
    TO_FLATBUFFER_CASE(DOUBLE);
    TO_FLATBUFFER_CASE(LARGE_BINARY);
    TO_FLATBUFFER_CASE(BINARY);
    case Type::STRING:
      return fbs::Type::UTF8;
    case Type::LARGE_STRING:
      return fbs::Type::LARGE_UTF8;
    case Type::DATE32:
      return fbs::Type::INT32;
    case Type::TIMESTAMP:
      return fbs::Type::INT64;
    case Type::TIME32:
      return fbs::Type::INT32;
    case Type::TIME64:
      return fbs::Type::INT64;
    default:
      return Status::TypeError("Unsupported Feather V1 type: ", type.ToString(),
                               ". Use V2 format to serialize all Arrow types.");
  }
}

inline flatbuffers::Offset<fbs::PrimitiveArray> GetPrimitiveArray(
    FBB& fbb, const ArrayMetadata& array) {
  return fbs::CreatePrimitiveArray(fbb, array.type, fbs::Encoding::PLAIN, array.offset,
                                   array.length, array.null_count, array.total_bytes);
}

// Convert Feather enums to Flatbuffer enums
inline fbs::TimeUnit ToFlatbufferEnum(TimeUnit::type unit) {
  return static_cast<fbs::TimeUnit>(static_cast<int>(unit));
}

const fbs::TypeMetadata COLUMN_TYPE_ENUM_MAPPING[] = {
    fbs::TypeMetadata::NONE,               // PRIMITIVE
    fbs::TypeMetadata::CategoryMetadata,   // CATEGORY
    fbs::TypeMetadata::TimestampMetadata,  // TIMESTAMP
    fbs::TypeMetadata::DateMetadata,       // DATE
    fbs::TypeMetadata::TimeMetadata        // TIME
};

inline fbs::TypeMetadata ToFlatbufferEnum(ColumnType::type column_type) {
  return COLUMN_TYPE_ENUM_MAPPING[column_type];
}

struct ColumnMetadata {
  flatbuffers::Offset<void> WriteMetadata(FBB& fbb) {  // NOLINT
    switch (this->meta_type) {
      case ColumnType::PRIMITIVE:
        // flatbuffer void
        return 0;
      case ColumnType::CATEGORY: {
        auto cat_meta = fbs::CreateCategoryMetadata(
            fbb, GetPrimitiveArray(fbb, this->category_levels), this->category_ordered);
        return cat_meta.Union();
      }
      case ColumnType::TIMESTAMP: {
        // flatbuffer void
        flatbuffers::Offset<flatbuffers::String> tz = 0;
        if (!this->timezone.empty()) {
          tz = fbb.CreateString(this->timezone);
        }

        auto ts_meta =
            fbs::CreateTimestampMetadata(fbb, ToFlatbufferEnum(this->temporal_unit), tz);
        return ts_meta.Union();
      }
      case ColumnType::DATE: {
        auto date_meta = fbs::CreateDateMetadata(fbb);
        return date_meta.Union();
      }
      case ColumnType::TIME: {
        auto time_meta =
            fbs::CreateTimeMetadata(fbb, ToFlatbufferEnum(this->temporal_unit));
        return time_meta.Union();
      }
      default:
        // null
        DCHECK(false);
        return 0;
    }
  }

  ArrayMetadata values;
  ColumnType::type meta_type;

  ArrayMetadata category_levels;
  bool category_ordered;

  TimeUnit::type temporal_unit;

  // A timezone name known to the Olson timezone database. For display purposes
  // because the actual data is all UTC
  std::string timezone;
};

Status WriteArrayV1(const Array& values, io::OutputStream* dst, ArrayMetadata* meta);

struct ArrayWriterV1 {
  const Array& values;
  io::OutputStream* dst;
  ArrayMetadata* meta;

  Status WriteBuffer(const uint8_t* buffer, int64_t length, int64_t bit_offset) {
    int64_t bytes_written = 0;
    if (buffer) {
      RETURN_NOT_OK(
          WritePaddedWithOffset(dst, buffer, bit_offset, length, &bytes_written));
    } else {
      RETURN_NOT_OK(WritePaddedBlank(dst, length, &bytes_written));
    }
    meta->total_bytes += bytes_written;
    return Status::OK();
  }

  template <typename T>
  typename std::enable_if<
      is_nested_type<T>::value || is_null_type<T>::value || is_decimal_type<T>::value ||
          std::is_same<DictionaryType, T>::value || is_duration_type<T>::value ||
          is_interval_type<T>::value || is_fixed_size_binary_type<T>::value ||
          std::is_same<Date64Type, T>::value || std::is_same<Time64Type, T>::value ||
          std::is_same<ExtensionType, T>::value,
      Status>::type
  Visit(const T& type) {
    return Status::NotImplemented(type.ToString());
  }

  template <typename T>
  typename std::enable_if<is_number_type<T>::value ||
                              std::is_same<Date32Type, T>::value ||
                              std::is_same<Time32Type, T>::value ||
                              is_timestamp_type<T>::value || is_boolean_type<T>::value,
                          Status>::type
  Visit(const T&) {
    const auto& prim_values = checked_cast<const PrimitiveArray&>(values);
    const auto& fw_type = checked_cast<const FixedWidthType&>(*values.type());

    if (prim_values.values()) {
      const uint8_t* buffer =
          prim_values.values()->data() + (prim_values.offset() * fw_type.bit_width() / 8);
      int64_t bit_offset = (prim_values.offset() * fw_type.bit_width()) % 8;
      return WriteBuffer(buffer,
                         BitUtil::BytesForBits(values.length() * fw_type.bit_width()),
                         bit_offset);
    } else {
      return Status::OK();
    }
    return Status::OK();
  }

  template <typename T>
  enable_if_base_binary<T, Status> Visit(const T&) {
    using ArrayType = typename TypeTraits<T>::ArrayType;
    const auto& ty_values = checked_cast<const ArrayType&>(values);

    using offset_type = typename T::offset_type;
    const offset_type* offsets_data = nullptr;
    int64_t values_bytes = 0;
    if (ty_values.value_offsets()) {
      offsets_data = ty_values.raw_value_offsets();
      // All of the data has to be written because we don't have offset
      // shifting implemented here as with the IPC format
      values_bytes = offsets_data[values.length()];
    }
    RETURN_NOT_OK(WriteBuffer(reinterpret_cast<const uint8_t*>(offsets_data),
                              sizeof(offset_type) * (values.length() + 1),
                              /*bit_offset=*/0));

    const uint8_t* values_buffer = nullptr;
    if (ty_values.value_data()) {
      values_buffer = ty_values.value_data()->data();
    }
    return WriteBuffer(values_buffer, values_bytes, /*bit_offset=*/0);
  }

  Status Write() {
    if (values.type_id() == Type::DICTIONARY) {
      return WriteArrayV1(*(checked_cast<const DictionaryArray&>(values).indices()), dst,
                          meta);
    }

    ARROW_ASSIGN_OR_RAISE(meta->type, ToFlatbufferType(*values.type()));
    ARROW_ASSIGN_OR_RAISE(meta->offset, dst->Tell());
    meta->length = values.length();
    meta->null_count = values.null_count();
    meta->total_bytes = 0;

    // Write the null bitmask
    if (values.null_count() > 0) {
      RETURN_NOT_OK(WriteBuffer(values.null_bitmap_data(),
                                BitUtil::BytesForBits(values.length()), values.offset()));
    }
    // Write data buffer(s)
    return VisitTypeInline(*values.type(), this);
  }
};

Status WriteArrayV1(const Array& values, io::OutputStream* dst, ArrayMetadata* meta) {
  std::shared_ptr<Array> sanitized;
  if (values.type_id() == Type::NA) {
    // As long as R doesn't support NA, we write this as a StringColumn
    // to ensure stable roundtrips.
    sanitized = std::make_shared<StringArray>(values.length(), nullptr, nullptr,
                                              values.null_bitmap(), values.null_count());
  } else {
    sanitized = MakeArray(values.data());
  }
  ArrayWriterV1 visitor{*sanitized, dst, meta};
  return visitor.Write();
}

Status WriteColumnV1(const ChunkedArray& values, io::OutputStream* dst,
                     ColumnMetadata* out) {
  if (values.num_chunks() > 1) {
    return Status::Invalid("Writing chunked arrays not supported in Feather V1");
  }
  const Array& chunk = *values.chunk(0);
  RETURN_NOT_OK(WriteArrayV1(chunk, dst, &out->values));
  switch (chunk.type_id()) {
    case Type::DICTIONARY: {
      out->meta_type = ColumnType::CATEGORY;
      auto dictionary = checked_cast<const DictionaryArray&>(chunk).dictionary();
      RETURN_NOT_OK(WriteArrayV1(*dictionary, dst, &out->category_levels));
      out->category_ordered =
          checked_cast<const DictionaryType&>(*chunk.type()).ordered();
    } break;
    case Type::DATE32:
      out->meta_type = ColumnType::DATE;
      break;
    case Type::TIME32: {
      out->meta_type = ColumnType::TIME;
      out->temporal_unit = checked_cast<const Time32Type&>(*chunk.type()).unit();
    } break;
    case Type::TIMESTAMP: {
      const auto& ts_type = checked_cast<const TimestampType&>(*chunk.type());
      out->meta_type = ColumnType::TIMESTAMP;
      out->temporal_unit = ts_type.unit();
      out->timezone = ts_type.timezone();
    } break;
    default:
      out->meta_type = ColumnType::PRIMITIVE;
      break;
  }
  return Status::OK();
}

Status WriteFeatherV1(const Table& table, io::OutputStream* dst) {
  // Preamble
  int64_t bytes_written;
  RETURN_NOT_OK(WritePadded(dst, reinterpret_cast<const uint8_t*>(kFeatherV1MagicBytes),
                            strlen(kFeatherV1MagicBytes), &bytes_written));

  // Write columns
  flatbuffers::FlatBufferBuilder fbb;
  std::vector<flatbuffers::Offset<fbs::Column>> fb_columns;
  for (int i = 0; i < table.num_columns(); ++i) {
    ColumnMetadata col;
    RETURN_NOT_OK(WriteColumnV1(*table.column(i), dst, &col));
    auto fb_column = fbs::CreateColumn(
        fbb, fbb.CreateString(table.field(i)->name()), GetPrimitiveArray(fbb, col.values),
        ToFlatbufferEnum(col.meta_type), col.WriteMetadata(fbb),
        /*user_metadata=*/0);
    fb_columns.push_back(fb_column);
  }

  // Finalize file footer
  auto root = fbs::CreateCTable(fbb, /*description=*/0, table.num_rows(),
                                fbb.CreateVector(fb_columns), kFeatherV1Version,
                                /*metadata=*/0);
  fbb.Finish(root);
  auto buffer = std::make_shared<Buffer>(fbb.GetBufferPointer(),
                                         static_cast<int64_t>(fbb.GetSize()));

  // Writer metadata
  RETURN_NOT_OK(WritePadded(dst, buffer->data(), buffer->size(), &bytes_written));
  uint32_t metadata_size = static_cast<uint32_t>(bytes_written);

  // Footer: metadata length, magic bytes
  RETURN_NOT_OK(dst->Write(&metadata_size, sizeof(uint32_t)));
  return dst->Write(kFeatherV1MagicBytes, strlen(kFeatherV1MagicBytes));
}

// ----------------------------------------------------------------------
// Reader V2

class ReaderV2 : public Reader {
 public:
  Status Open(const std::shared_ptr<io::RandomAccessFile>& source) {
    source_ = source;
    ARROW_ASSIGN_OR_RAISE(auto reader, RecordBatchFileReader::Open(source_));
    schema_ = reader->schema();
    return Status::OK();
  }

  int version() const override { return kFeatherV2Version; }

  std::shared_ptr<Schema> schema() const override { return schema_; }

  Status Read(const IpcReadOptions& options, std::shared_ptr<Table>* out) {
    ARROW_ASSIGN_OR_RAISE(auto reader, RecordBatchFileReader::Open(source_, options));
    RecordBatchVector batches(reader->num_record_batches());
    for (int i = 0; i < reader->num_record_batches(); ++i) {
      ARROW_ASSIGN_OR_RAISE(batches[i], reader->ReadRecordBatch(i));
    }

    return Table::FromRecordBatches(reader->schema(), batches).Value(out);
  }

  Status Read(std::shared_ptr<Table>* out) override {
    return Read(IpcReadOptions::Defaults(), out);
  }

  Status Read(const std::vector<int>& indices, std::shared_ptr<Table>* out) override {
    auto options = IpcReadOptions::Defaults();
    options.included_fields = indices;
    return Read(options, out);
  }

  Status Read(const std::vector<std::string>& names,
              std::shared_ptr<Table>* out) override {
    std::vector<int> indices;
    std::shared_ptr<Schema> sch = this->schema();
    for (auto name : names) {
      int field_index = sch->GetFieldIndex(name);
      if (field_index == -1) {
        return Status::Invalid("Field named ", name, " is not found");
      }
      indices.push_back(field_index);
    }
    return Read(indices, out);
  }

 private:
  std::shared_ptr<io::RandomAccessFile> source_;
  std::shared_ptr<Schema> schema_;
};

}  // namespace

Result<std::shared_ptr<Reader>> Reader::Open(
    const std::shared_ptr<io::RandomAccessFile>& source) {
  // Pathological issue where the file is smaller than header and footer
  // combined
  ARROW_ASSIGN_OR_RAISE(int64_t size, source->GetSize());
  if (size < /* 2 * 4 + 4 */ 12) {
    return Status::Invalid("File is too small to be a well-formed file");
  }

  // Determine what kind of file we have. 6 is the max of len(FEA1) and
  // len(ARROW1)
  constexpr int magic_size = 6;
  ARROW_ASSIGN_OR_RAISE(auto buffer, source->ReadAt(0, magic_size));

  if (memcmp(buffer->data(), kFeatherV1MagicBytes, strlen(kFeatherV1MagicBytes)) == 0) {
    std::shared_ptr<ReaderV1> result = std::make_shared<ReaderV1>();
    RETURN_NOT_OK(result->Open(source));
    return result;
  } else if (memcmp(buffer->data(), internal::kArrowMagicBytes,
                    strlen(internal::kArrowMagicBytes)) == 0) {
    std::shared_ptr<ReaderV2> result = std::make_shared<ReaderV2>();
    RETURN_NOT_OK(result->Open(source));
    return result;
  } else {
    return Status::Invalid("Not a Feather V1 or Arrow IPC file");
  }
}

WriteProperties WriteProperties::Defaults() {
  WriteProperties result;
#ifdef ARROW_WITH_LZ4
  result.compression = Compression::LZ4_FRAME;
#else
  result.compression = Compression::UNCOMPRESSED;
#endif
  return result;
}

Status WriteTable(const Table& table, io::OutputStream* dst,
                  const WriteProperties& properties) {
  if (properties.version == kFeatherV1Version) {
    return WriteFeatherV1(table, dst);
  } else {
    IpcWriteOptions ipc_options = IpcWriteOptions::Defaults();
    ipc_options.unify_dictionaries = true;
    ipc_options.allow_64bit = true;
    ARROW_ASSIGN_OR_RAISE(
        ipc_options.codec,
        util::Codec::Create(properties.compression, properties.compression_level));

    std::shared_ptr<RecordBatchWriter> writer;
    ARROW_ASSIGN_OR_RAISE(writer, MakeFileWriter(dst, table.schema(), ipc_options));
    RETURN_NOT_OK(writer->WriteTable(table, properties.chunksize));
    return writer->Close();
  }
}

}  // namespace feather
}  // namespace ipc
}  // namespace arrow

redpajama_set_name: RedPajamaGithub


Working within the field of employment law is about working with people - often the most valuable asset in a company. Ræder's experienced and regarded specialists advise in all areas of employment law and pension law and have a thorough understanding of the extensive and complex regulations. The best solutions are often found not only by applying rules and regulations alone but taking a holistic approach, working within the framework but also focusing on people.
Employment law is comprehensive, complex and rules and regulations are constantly developing. Businesses of all sizes therefore need advice and guidance from specialists. Ræder's practice has a strong standing and several members of the team are respected voices in the public debate in this field.
Regardless of whether you are gridlocked in a dispute, sense a conflict, are in the middle of a reorganisation process, or just want to be safe rather than sorry - we provide robust and practical advice. Our lawyers regularly assist business owners, HR managers and management on legal and strategic employment issues finding the right solutions and meeting the needs of our client's business.
If you are setting up an enterprise or business in Norway, transferring workers to Norway, or planning on becoming an expat in Norway, there are various obligations that employers and employees must comply to. This guide summarizes the obligations and processes that aply when working and living in Norway.